国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表

圖片精選

主站蜘蛛池模板: 濮阳市| 湖北省| 余干县| 云阳县| 卢氏县| 都江堰市| 肥乡县| 平乡县| 双牌县| 远安县| 九江县| 靖远县| 咸丰县| 牟定县| 扶沟县| 巨野县| 新宁县| 疏勒县| 阿坝| 文化| 宣威市| 竹北市| 满城县| 汉川市| 西和县| 黔西| 哈尔滨市| 彝良县| 丹阳市| 庆阳市| 方正县| 荔浦县| 玉树县| 环江| 抚顺市| 奉贤区| 赤城县| 昌都县| 沈丘县| 都江堰市| 徐汇区|