数组
const app = Vue.createApp({ data() { return { listArry: ['dell', 'lee', 'teacher'], listObject:{ firstName:'dell', lastName:'lell', job:'teacher', } } }, template: ` <div> <div v-for="(item,index) in listArry"> {{item}}-{{index}} </div> </div> ` }); const vm = app.mount('#root');</script>
对象

const app = Vue.createApp({ data() { return { listArry: ['dell', 'lee', 'teacher'], listObject:{ firstName:'dell', lastName:'lell', job:'teacher', } } }, template: ` <div> <div v-for="(value,key,index) in listObject"> {{value}}-{{key}}-{{index}} </div> </div> ` }); const vm = app.mount('#root');
const app = Vue.createApp({ data() { return { listArry: ['dell', 'lee', 'teacher'], listObject: { firstName: 'dell', lastName: 'lell', job: 'teacher', } } }, methods: { handleAddBtnClick() { //1、使用数组的变更函数 push,pop,shift(从开头去除),unshift(从开头添加),splice, sort, reverse // this.listArry.push('hello') // this.listArry.pop(); // this.listArry.shift('hello') // this.listArry.unshift('hello') //2、直接替换数组 // this.listArry=['bye','world'] // this.listArry=['bye'].concat(['world']) // this.listArry = ['bye', 'world'].filter(item => item === 'bye'); // 3、直接更新数组的内容 // this.listArry[1]='word' // 直接添加对象的内容,也可以自动的展示出来 this.listObject.age = 100; this.listObject.sex = 'male'; } }, template: ` <div> <template v-for="(value, key, index) in listObject" :key="index" > <div v-if="key !== 'lastName'"> {{value}} -- {{key}} </div> </template> <div v-for="item in 10">{{item}}</div> <button @click="handleAddBtnClick">新增</button> </div> ` }); const vm = app.mount('#root');