<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 数据渲染界面 -->
<!-- 绑定表单元素 -->
<div id="abc">
<div class="add">
<input type="text" v-model="itemname">
<input type="button" value="添加" @click="addItem()">
</div>
<div class="add">
<input type="text" placeholder="请输入你想输入的名称">
</div>
<div>
<table class="tb">
<tr>
<th>编号</th>
<th>品牌名称</th>
<th>创立时间</th>
<th>操作</th>
</tr>
<tr v-for="(v,i) in list">
<td>{{i+1}}</td>
<td>{{v.name}}</td>
<td>{{v.date}}</td>
<td>
<a href="#">删除</a>
</td>
</tr>
<tr v-if="list.length===0">
<td colspan="4">没有品牌数据</td>
</tr>
</table>
</div>
</div>
<script src="./js/vue.js"></script>
<script>
var list = [{
name: 'TCL',
date: new Date()
}, {
name: 'xx00',
date: new Date()
}, {
name: 'TCL',
date: new Date()
},
];
var vm = new Vue({
//v-on里面的methods方法
el: '#abc',
//模板ajax返回的数据
data: {
msg: '我是歌谣',
//等同于list:list
list,
itemname: ''
},
methods: {
addItem() {
this.list.unshift({
name: this.itemname,
date: new Date()
})
}
}
})
</script>
<!-- 列表渲染 -->
<!-- 1渲染数组 -->
<!-- 2c处理无数据的时候 -->
</body>
</html>
标签:vue,21,--,list,methods,Date,date,new,name From: https://blog.51cto.com/u_15460007/6050411