国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

使用Vue做一個簡單的todo應(yīng)用的三種方式的示例代碼

2024-05-06 15:28:34
字體:
供稿:網(wǎng)友

1. 引用vue.js

<!DOCTYPE html><html><head><script src="http://vuejs.org/js/vue.js"></script> <meta charset="utf-8"> <title>JS Bin</title></head><body> <div id="root">  <input type="text" v-model="inputValue">  <button @click="handlerAdd">提交</button>  <ul>   <li      v-for="(item,index) of lists"      :key="index"      @click="handlerDel(index)"    >    {{item}}   </li>  </ul> </div>  <script>  new Vue({   el: '#root',   data: {    inputValue: '',    lists: []   },   methods: {    handlerAdd: function() {     this.lists.push(this.inputValue);     this.inputValue = '';    },    handlerDel: function(index) {     this.lists.splice(index, 1);    }   }  }); </script></body></html>

2. 全局組件注冊

<!DOCTYPE html><html><head><script src="http://vuejs.org/js/vue.js"></script> <meta charset="utf-8"> <title>JS Bin</title></head><body> <div id="root">  <input type="text" v-model="inputValue">  <button @click="handlerAdd">提交</button>  <ul>   <todo-item    v-for="(item,index) of lists"    :content = "item"    :index = "index"    :key = "index"    @delete="handlerDel"   >   </todo-item>  </ul> </div>  <script>  Vue.component('todoItem', {   props: {    content: String,    index: Number   },   template: '<li @click="handlerClick">{{content}}</li>',   methods: {    handlerClick: function(){     this.$emit('delete', this.index);    }   }  });  new Vue({   el: '#root',   data: {    inputValue: '' ,    lists: []   },   methods: {    handlerAdd: function() {     this.lists.push(this.inputValue);     this.inputValue = '';    },    handlerDel: function(index) {     this.lists.splice(index,1);    }   }  }); </script></body></html>

3. vue-cli腳手架

// Todo.Vue<template> <div>  <input type="text" v-model="inputValue">  <button @click="handlerAdd">提交</button>  <ul>   <todo-item    v-for="(item,index) of lists"    :key="index"    :content="item"    :index="index"    @delete="handlerDel"   ></todo-item>  </ul> </div></template><script>import TodoItem from './components/todoItem'export default { data () {  return {   inputValue: '',   lists: []  } }, methods: {  handlerAdd () {   this.lists.push(this.inputValue)   this.inputValue = ''  },  handlerDel (index) {   this.lists.splice(index, 1)  } }, components: {  'todo-item': TodoItem }}</script><style></style>// TodoItem.vue<template> <li @click="handlerClick" class="item">{{content}}</li></template><script>export default { props: ['content', 'index'], methods: {  handlerClick () {   this.$emit('delete', this.index)  } }}</script><style scoped> ul,li {  list-style: none; } .item {  color: blueviolet; }</style>            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 同仁县| 榆社县| 新乡市| 饶平县| 松溪县| 偃师市| 绥宁县| 平利县| 峨眉山市| 张家界市| 榕江县| 肃北| 贡嘎县| 上犹县| 武宣县| 郯城县| 罗定市| 吉水县| 长治市| 河北省| 乌鲁木齐市| 精河县| 和静县| 安义县| 宿松县| 苏尼特右旗| 禹城市| 汉源县| 江华| 通江县| 焉耆| 大庆市| 长顺县| 仁化县| 乌兰浩特市| 砀山县| 通州市| 加查县| 广丰县| 榆社县| 九龙城区|