<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        使用Vue做一個簡單的todo應用的三種方式的示例代碼

        來源:懂視網 責編:小采 時間:2020-11-27 22:06:06
        文檔

        使用Vue做一個簡單的todo應用的三種方式的示例代碼

        使用Vue做一個簡單的todo應用的三種方式的示例代碼:1. 引用vue.js <!DOCTYPE html> <html> <head> <script src=http://vuejs.org/js/vue.js></script> <meta charset=utf-8> <title>JS Bin</ti
        推薦度:
        導讀使用Vue做一個簡單的todo應用的三種方式的示例代碼:1. 引用vue.js <!DOCTYPE html> <html> <head> <script src=http://vuejs.org/js/vue.js></script> <meta charset=utf-8> <title>JS Bin</ti

        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>
        

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        使用Vue做一個簡單的todo應用的三種方式的示例代碼

        使用Vue做一個簡單的todo應用的三種方式的示例代碼:1. 引用vue.js <!DOCTYPE html> <html> <head> <script src=http://vuejs.org/js/vue.js></script> <meta charset=utf-8> <title>JS Bin</ti
        推薦度:
        標簽: 方法 VUE 代碼
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 任你躁在线精品免费| 亚洲人成电影网站免费| 亚洲黄片手机免费观看| 亚洲国产av一区二区三区| 国产精品亚洲AV三区| 日韩免费a级在线观看| 亚洲日韩精品无码专区加勒比| 18禁止看的免费污网站| 亚洲一区二区三区在线网站| 中文毛片无遮挡高潮免费| 中中文字幕亚洲无线码| 91情侣在线精品国产免费| 亚洲日本在线电影| 全部免费国产潢色一级| 免费播放国产性色生活片| 久久激情亚洲精品无码?V| 国产日韩AV免费无码一区二区 | 国产在线观看免费观看不卡| 中文字幕在线日亚洲9| 精品国产免费一区二区| 一级毛片免费播放试看60分钟| 亚洲色爱图小说专区| 亚洲电影免费观看| 亚洲精品无码成人| 国产亚洲老熟女视频| 91免费在线播放| 美女被免费网站在线视频免费| 国产成人精品日本亚洲专区| 2021精品国产品免费观看| 亚洲AV无码国产精品永久一区| 国产精品亚洲二区在线观看| 88av免费观看| 色偷偷尼玛图亚洲综合| 亚洲av永久无码精品国产精品| 无码人妻一区二区三区免费| 无码人妻一区二区三区免费视频| 久久久久亚洲精品美女| 特级淫片国产免费高清视频| 久久九九全国免费| 亚洲精品V天堂中文字幕| 综合亚洲伊人午夜网|