vue3.x data语法


 

注:实例环境 vue cli构建的项目

app.vue

<template> <Example></Example> </template> <script> import Example from './components/Example' export default { name: 'App', components: { Example } } </script> <style> </style> 

Example.vue

<template> <div> <p>{{string}}</p> <p>{{bool}}</p> <p> <span v-for="value in array" :key="value">{{value}}</span> </p> <p> {{obj.name}}:{{obj.age}} </p> <ul> <li v-for="item in arrObj" :key="item.id">{{item.id}}:{{item.title}}</li> </ul> </div> </template> <script> export default { name: "Example", data:function () { return { string:'string', bool:true, array:[1,2,3], obj:{name:'天行子',age:23}, arrObj:[ {id:1,title:'title1'}, {id:2,title:'title2'}, {id:3,title:'title3'} ] } }, } </script> <style scoped> </style> 

刷新浏览器,看见如下数据

string true 123 天行子:23 1:title1 2:title2 3:title3


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM