当前位置:网站首页>Daily notes~
Daily notes~
2022-07-04 16:18:00 【Seven days and seven longevity】
vite
Create a project
npm init vite-app Project name
Enter the project directory
cd Project name
Installation dependency
npm install
function
npm run dev
setup
understand vue3.0 A new configuration item in , Value is a function
setup It's all Composition API( Combine API) The performance stage
Components used in data Methods, etc. All shall be configured in setup in
setup Two return values of function
If you return an object Then the properties in the object Methods can be used directly in templates ( Focus on )
If you return a rendering function You can customize the rendering content
Be careful
Try not to contact vue2.x Configuration mix
vue2.x To configure (data,methods,computed..) You can access setup Properties in Method
But in setup Cannot access vue2.x To configure (data,methods,computed...)
If there are duplicate names setup first
setup It can't be a async function Because the return value is no longer return The object of It is promise The template can't see return Properties in objects
ref function
effect Define a responsive data
grammar const xxx=ref(initValue)
Create a reference object containing responsive data (reference object abbreviation ref object )
js Operation data in xxx.value
Read data from the template Unwanted .value direct <div>{
{xxx}}</div>
remarks
The accepted data can be Basic types It can also be object type
Basic types of data Responsiveness still depends on object.defineProperty() Of get and set Accomplished
Object type data Internal help Vue3.0 A new function in --reactive function
reactive function
effect Define the responsive data of an object type ( Basic type don't use it Use ref function )
grammar const Proxy object =reactive( Source object ) Receive an object ( Or an array ), Returns a proxy object (proxy Instance object of abbreviation proxy object )
reactive The defined responsive data is deep-seated
Give... Internally ES6 Of Proxy Realization Operate the internal data of the source object through the proxy object
vue3 The principle of response in
Realization principle
object type adopt object.defineProperty() Reading properties , Modify to intercept ( The data was hijacked )
An array type Intercept by rewriting a series of methods to update the array ( The change method of the array is wrapped )
Object,defineProperty(data,'count',{
get(){}
set(){}
})
Existing problems
New properties , Delete attribute The interface doesn't update
Modify the array directly by subscript , The interface doesn't update automatically
vue3 The principle of response
Realization principle
adopt Proxy( agent ) Intercepts any attribute changes in the object Include Read and write property values Attribute addition Deletion of attributes, etc
adopt Reflect( Reflection ) Operate on the properties of the source object
let person = {
name: "zs",
age: 19,
};
// simulation vue3 Implement responsive in
const p = new Proxy(person, {
// Someone read p Called when a property of
get(target, propName) {
console.log(target, propName);
// return target[propName];
return Reflect.get(target, propName);
},
// Someone modified it p A property of , Or to p Called when a property is appended
set(target, propName, value) {
// target[propName] = value;
Reflect.set(target, propName, value);
},
// Someone deleted p When a property of
deleteProperty(target, propName) {
// return delete target[propName];
return Reflect.defineProperty(target, propName);
},
});
reactive contrast ref
Compare... From the perspective of defining data
ref Used to define Basic types of data
reactive Used to define object ( Or an array ) Type data
remarks ref It can also be used to define object or array type data It will automatically pass through reactive Turn to proxy object
Compare... In principle
ref adopt object.defineProperty() Of get and set To achieve responsive ( The data was hijacked )
reactive By using Proxy To achieve responsive ( The data was hijacked ), And pass Reflect Operate the data inside the metadata
Compare... From the perspective of use
ref Defined data Operational data needs .value When reading data, you do not need to read directly from the template .value
reactive Defined data Operating data and reading data No need to .value
setup Two things to pay attention to
setup Actual execution
stay beforeCreate Once before ,this yes undefined
setup Parameters of
props Value as object contain Passed from outside the component And the internal declaration of the component has accepted the attribute
context Context object
attrs Value as object contain Passed from outside the component But not in props Properties declared in the configuration amount to this.$attrs
slots Received slot contents amount to this.$slots
emit Distribute functions that automatically take events amount to this.$emit
边栏推荐
- Scientific research cartoon | what else to do after connecting with the subjects?
- Anta is actually a technology company? These operations fool netizens
- Nine CIO trends and priorities in 2022
- The per capita savings of major cities in China have been released. Have you reached the standard?
- Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
- Unity脚本介绍 Day01
- C implementation defines a set of intermediate SQL statements that can be executed across libraries
- Neuf tendances et priorités du DPI en 2022
- The four most common errors when using pytorch
- Will the memory of ParticleSystem be affected by maxparticles
猜你喜欢
时钟轮在 RPC 中的应用
What is the catalog of SAP commerce cloud
[hcie TAC] question 5 - 1
Stress, anxiety or depression? Correct diagnosis and retreatment
AI system content recommendation issue 24
PR FAQ: how to set PR vertical screen sequence?
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
函数式接口,方法引用,Lambda实现的List集合排序小工具
中国主要城市人均存款出炉,你达标了吗?
Redis sentinel mode realizes one master, two slave and three Sentinels
随机推荐
Stew in disorder
怎么判断外盘期货平台正规,资金安全?
[hcie TAC] question 5 - 1
Unity prefab day04
在芯片高度集成的今天,绝大多数都是CMOS器件
Interpretation of the champion scheme of CVPR 2020 night target detection challenge
MySQL学习笔记——数据类型(数值类型)
【读书会第十三期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
MySQL learning notes - data type (2)
Laravel simply realizes Alibaba cloud storage + Baidu AI Cloud image review
函数式接口,方法引用,Lambda实现的List集合排序小工具
C language: implementation of daffodil number function
How did the beyond concert 31 years ago get super clean and repaired?
Shell 编程基础
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Redis shares four cache modes
C implementation defines a set of intermediate SQL statements that can be executed across libraries
科研漫画 | 联系到被试后还需要做什么?
In today's highly integrated chips, most of them are CMOS devices
深入JS中几种数据类型的解构赋值细节