当前位置:网站首页>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
}
}
}
复制代码边栏推荐
- Scheduled tasks, VIM directly creates and modifies users
- 2022 P gas cylinder filling examination practice questions simulated examination platform operation
- [mqtt from getting started to improving series | 06] subscribe subscription workflow of mqtt3.1.1
- 滑动窗口最大值问题
- Notes on random nodes of force buckle 382 linked list
- Can [C language - user defined type] be adjusted like this?
- 现在网上办理基金开户,身份证信息安全吗?
- Display module in pyGame
- MongoDB分片集群搭建
- Classification of blocks
猜你喜欢

MySQL CPU使用率飙升,如何定位是被谁占用了
[email protected]之moveActivityIdTo任务回退特殊案例分析"/>学习记录[email protected]之moveActivityIdTo任务回退特殊案例分析
![[flask introduction series] request hook and context](/img/a9/96e330525ee1337daab275b87db892.png)
[flask introduction series] request hook and context

End repeated development and personalize the login system in twoorthree times

LabVIEW uses multithreading. Will the program run faster

QChartView添加在QGridLayout中时覆盖了之前的控件

C - usage of this

状态机练习

MVCC多版本并发控制

Classification of interrupts
随机推荐
Problème de la valeur maximale de la fenêtre coulissante
3U VPX cooling conduction high performance srio/ Ethernet data exchange board
现在网上办理基金开户,身份证信息安全吗?
SQL wrong questions set of Niuke brush questions
Analysis of network communication flow of different containers on the same host
Is it safe to open a fund account online now?
Damn it, why is there less space on the USB flash drive? It's the EFI partition. Delete it
Cilium & Hubble
论文阅读 TEMPORAL GRAPH NETWORKS FOR DEEP LEARNING ON DYNAMIC GRAPHS
状态机练习
Li Kou 455 distribute cookie notes
C - usage of this
Labview32-bit and 64 bit compatibility
MySQL index (II)
Oserror: sndfile library not found solution
深入理解事务隔离级别
Si446 usage record (III): match function
Qchartview overwrites the previous control when it is added in qgridlayout
Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
Encrypt Ogg users