vue中输入框v-mode绑定
<!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="app">
手机:<input type="text" v-model="newProject.name">
库存:<input type="text" value="0" v-model="newProject.num">
<input type="submit" @click="add()" value="提交">
<ul>
<li v-for="(item ,i) in goods" :k="i">
商品:{{item.name}},库存:{{item.num}}
</li>
</ul>
</div>
<script src="./js/vue.js"></script>
<script>
var vm = new Vue({
el:"#app",
data:{
newProject:{
name:'',
num:0
},
goods:[
{name:'iphone',num:10},
{name:'xiaomi',num:11},
{name:'huawei',num:12},
]
},
methods:{
add:function(){
this.goods.push({
name:this.newProject.name,
num:this.newProject.num,
})
}
}
})
</script>
</body>
</html>
时间如白驹过隙,忽然而已,且行且珍惜......