1. When to execute setUp
2. The data in data and the methods in methods cannot be used in setUp <script> export default { name: 'App', data:function(){ return { mess: "I am data" } }, methods:{ func(){ console.log("func in methods") }, }, setup(){ console.log('this',this);//undefined this.func();//Cannot be called}, } </script> 3. Notes on the setUp function (1) Because we cannot use data and methods in the setUp function. (2) The setUp function can only be synchronous, not asynchronous.
4 Reactivity in Vue3
Reactive points to note 5 Reactive string data is not updated <template> <div> <div> <li>{{str}}</li> <button @click="func1">Button</button> </div> </div> </template> <script> import {reactive} from 'vue' export default { name: 'App', setup(){ // The essence of reactive is to wrap the incoming data into a proxy object. // Since an object is not passed when it is created, responsiveness will not be achieved. let str = reactive(123) function func1(){ console.log(str);//123 str=666; } return {str,func1} }, } </script> We found that when the button was clicked, the view was not updated. 6 reactive array <template> <div> <div> <li>{{arr}}</li> <button @click="func1">Button</button> </div> </div> </template> <script> import {reactive} from 'vue' export default { name: 'App', setup(){ let arr=reactive([{name:'张三',age:19},{name:'李四',age:39}]) function func1(){ arr[0].name="I am Zhang San's brother" } return {arr,func1 } }, } </script> 7. Reactive updates other objects <template> <div> <div> <li>{{sate.time}}</li> <button @click="func1">Button</button> </div> </div> </template> <script> import {reactive} from 'vue' export default { name: 'App', setup(){ let sate = reactive({ time:new Date() }) function func1(){ //Other objects are passed in, and sate.time is directly updated="2021年-6月-9日"; } return {sate,func1 } }, } </script> The above is a detailed explanation of the vue3 setUp and reactive functions. For more information about vue3 setUp and reactive functions, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Mysql implements null value first/last method example
>>: Install Docker for Windows on Windows 10 Home Edition
Copy code The code is as follows: <style> ....
MySQL installation tutorial, for your reference, ...
I joined a new company these two days. The compan...
Fault site: Log in to the MySQL server and get th...
Table of contents 1. Background of the problem: 2...
I read many tutorials, but found that I could nev...
This section provides an overview of some other i...
In one sentence: Data hijacking (Object.definePro...
Change the default style of select, usually throug...
Table of contents Importing JavaScript 1. Interna...
MySQL reports an error when executing multi-table...
app.js: startup file, or entry file package.json:...
Table of contents 1. Set Deduplication 2. Double ...
In addition to setting regulations for various ta...
Before we begin, we create two tables to demonstr...