vue3保留了vue2的語法,但是不能混著用,setup中定義原有vue2中data數(shù)據(jù)的方法有所改變
直接上代碼
import { reactive } from 'vue'
export default {
setup() {
const info = reactive ({
name:'張三',
age:18
}),
}
return { info};
}
對(duì)比原有vue2代碼
data() {
? ? ? ? ? ? return {
? ? ? ? ? ? ? ? name: "張三",
? ? ? ? ? ? ? ? age:18
? ? ? ? ? ? }
? ? }文章來源:http://www.zghlxwxcb.cn/news/detail-530674.html
在setup函數(shù)中使用數(shù)據(jù)也無需this.xxx,而是用你定義的名字,我定義的是info(也可也換成其他)則用info.name文章來源地址http://www.zghlxwxcb.cn/news/detail-530674.html
到了這里,關(guān)于vue3的setup函數(shù)中定義data數(shù)據(jù),使用data數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!