<!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">
<ul>
<li v-for='item in list'>{{item}}</li>
</ul>
<div>
<input type="text" v-model='userInput'>
<span>
<button type="button" v-on:click='addItem'>add</button>
</span>
</div>
</div>
<script src="./js/vue.min.js"></script>
<script>
var inputValue = ''
var vue = new Vue({
el: '#app',
data: {
list: ['aaa', 'bbb', 'ccc', 'ddd'],
userInput: inputValue
},
methods: {
addItem: function() {
// alert('ok')
this.list.push(this.userInput)
this.userInput = ''
},
}
})
</script>
</body>
</html>
列表渲染和事件监听v-on
最新推荐文章于 2022-10-12 17:47:37 发布