1. 程式人生 > 其它 >列表渲染和事件監聽v-on

列表渲染和事件監聽v-on

技術標籤:前端vue列表

<!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>