当前位置:网站首页>Setup的使用技巧
Setup的使用技巧
2022-07-17 21:56:00 【InfoQ】
一、setup函数的特性以及作用
二、setup函数的注意点
用法1:结合ref使用
<template>
<div id="app">
{{name}}
<p>{{age}}</p>
<button @click="plusOne()">+</button>
</div>
</template>
<script>
import {ref} from "vue"
export default {
name:"app",
data(){
return {
name:"xiaosan"
}
},
setup(){
const name =ref("小四")
const age=ref(18)
function plusOne(){
age.value++ //想改变值或获取值 必须.value
}
return { //必须返回 模板中才能使用
name,age,plusOne
}
}
}
</script>
复制代码用法2:代码分割
importuseAfrom "./a";
importuseBfrom "./b";
importuseCfrom "./c";
exportdefault {
setup(props) {
let { a, methodsA } = useA();
let { b, methodsB } = useA();
let { c, methodsC } = useC();
return {
a,
methodsA,
b,
methodsB,
c,
methodsC
}
}
}
复制代码边栏推荐
- 见鬼,U盘空间怎么少了,原来是EFI分区搞的鬼,删除它
- 敏捷的第一步:把 “迭代” 变为 “冲刺” 开始!
- OSError: sndfile library not found 解决方案
- MySQL storage functions and triggers
- 详解C语言文件操作
- Use tongweb's hot deployment function with caution
- Li Kou 455 distribute cookie notes
- SCM software timer v2.0
- Scheduled tasks, VIM directly creates and modifies users
- Compositionapi component development paradigm
猜你喜欢

揭开服务网格~Istio Service Mesh神秘的面纱

Comparaison de deux types de machines virtuelles

ORA-08103

JVM performance optimization

两种虚拟机的比较

Win10 Microsoft Store cannot be opened (enable TLS 1.2)

Redis source code and design analysis -- 3 Dictionaries

敏捷的第一步:把 “迭代” 变为 “冲刺” 开始!

定时任务,vim直接创建修改用户

End repeated development and personalize the login system in twoorthree times
随机推荐
SQL related time date type
Cilium & Hubble
ospf 附录 防环 重发布
[Luogu p3220] and not (construction) (digit DP) (inference)
Single channel 6Gsps 12 bit AD acquisition and single channel 6Gsps 16 bit Da (ad9176) output sub card based on vita57.1 standard
Alibaba microservice component Nacos registry
The manual is not complete. How to manually dig out the monitoring information of tongweb?
程序员 运维那些高薪的背后
Principle and simple implementation of custom MVC
Sub database and sub table
C speech Young's matrix · left-hand string · judge whether the string is rotated
论文阅读 TEMPORAL GRAPH NETWORKS FOR DEEP LEARNING ON DYNAMIC GRAPHS
Pyside2嵌入Matplotlib的绘图
CompositionAPI 组件开发范式
Wechat applet -- wxss template style
【MQTT从入门到提高系列 | 06】MQTT3.1.1之SUBSCRIBE订阅工作流
44、使用OrienMask进行实例分割目标检测,并进行mnn部署和ncnn部署
Labview32-bit and 64 bit compatibility
国科大. 深度学习. 期末试题与简要思路分析
[Axi] interpret the additional signals of the Axi protocol (QoS signal, region signal, and user signal)