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

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 12:39:54
字體:
供稿:網(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>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 福鼎市| 南阳市| 太白县| 威海市| 吉林市| 菏泽市| 康平县| 丹巴县| 丘北县| 安平县| 满洲里市| 永济市| 潜山县| 海伦市| 汝州市| 江都市| 五台县| 辽阳县| 临沂市| 周至县| 静宁县| 建湖县| 栾川县| 伊宁市| 花莲县| 开平市| 利津县| 正宁县| 乐都县| 华阴市| 磴口县| 岳普湖县| 武邑县| 城口县| 陆丰市| 淳化县| 寿宁县| 读书| 阿鲁科尔沁旗| 九龙坡区| 陵川县|