1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>vue基础介绍</title> </head> <body> <div id="one"> <span v-bind:title="message"> 鼠标悬停几秒钟查看此处动态绑定的提示信息! </span> <div id="app-3"> <p v-if="seen">你能看到这个</p> <p v-if="!seen">你看不到这个</p> <ol> <li v-for="todo in todos"> {{ todo.text }} </li> </ol> <button v-on:click="reverseMessage">反转消息</button> <p>{{ message }}</p> <input v-model="message"> <todo-item1></todo-item1> <todo-item2 v-for="item in todos" v-bind:todo="item" v-bind:key="item.id" ></todo-item2> </div> </div> </body> </html> <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> <script> Vue.component('todo-item1', { template: '<li>这是一个组件</li>' }) Vue.component('todo-item2', { props: ['todo'], template: '<li>{{ todo.text }}</li>' }) var vue=new Vue({ el:'#one', data:{ message: '页面加载于 ' + new Date().toLocaleString(), seen:true, todos: [ { text: '学习 JavaScript' }, { text: '学习 Vue' }, { text: '整个牛项目' } ], }, methods: { reverseMessage: function () { this.message = this.message.split('').reverse().join('') } } }) </script>
|