uniapp dynamic modification of element node style detailed explanation

uniapp dynamic modification of element node style detailed explanation

1. Modify by binding the style attribute

The first step: you must get the element node

There is no windou object in the uniApp project, so the dom node cannot be directly obtained through the document. The refs of vue are only valid for custom components and not for tags in uniapp.

Check the uniapp official website for a uni.createSelectorQuery() API; you can use this property to get the style of the label and then modify it by dynamically binding the style;

html:

<button type="default" @click="handleFont">Click to increase font</button>
<view class="weibo_box" id='index0' :style="{fontSize:vHeight + 'px'}">

Corresponding js:

data(){
	return {
		vHeight:22
	}
},


handleFont(){
	const that=this
	uni.createSelectorQuery().select('#index0').boundingClientRect(function (data) { 
	  console.log('element information 0:', data)
		  that.vHeight +=10
	}).exec()
}

The effect achieved:

insert image description here

Second, use ref to get the DOM element node

Code:

<button type="default" @click="handleFont">Click to increase font</button>
<view class="weibo_box" id='index1' ref="mydom">
	The second one
data(){
	return {
		vHeight:22
	}
},
//Some codes are irrelevant, omit handleFont(){
	const that=this
	that.$refs.mydom.$el.style.fontSize=that.vHeight+=1+'px'
}

The effect achieved:

insert image description here

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the difference between uniapp and vue
  • Detailed explanation of uniapp painless token refresh method
  • Detailed explanation of uniapp's global variable implementation
  • Detailed explanation of styles in uni-app

<<:  How to quickly copy large files under Linux

>>:  Summary of knowledge points related to null (IFNULL, COALESCE and NULLIF) in MySQL

Recommend

Solution to the problem that docker logs cannot be retrieved

When checking the service daily, when I went to l...

How to install and configure ftp server in CentOS8.0

After the release of CentOS8.0-1905, we tried to ...

Detailed explanation of the WeChat applet request pre-processing method

question Because some of our pages request data i...

Detailed explanation of JavaScript implementation of hash table

Table of contents 1. Hash table principle 2. The ...

The iframe frame sets the white background to transparent in IE browser

Recently, I need to frequently use iframe to draw ...

MySQL helps you understand index pushdown in seconds

Table of contents 1. The principle of index push-...

MySQL learning database search statement DQL Xiaobai chapter

Table of contents 1. Simple retrieval of data 2. ...

How to change the password of mysql5.7.20 under linux CentOS 7.4

After MySQL was upgraded to version 5.7, its secu...

Javascript uses the integrity attribute for security verification

Table of contents 1. Import files using script ta...

How to correctly modify the ROOT password in MySql8.0 and above versions

Deployment environment: Installation version red ...

jQuery implements a simple comment area

This article shares the specific code of jQuery t...

React non-parent-child component parameter passing example code

React is a JAVASCRIPT library for building user i...

How to position the header at the top using CSS sticky layout

Application scenarios: One of the new requirement...