最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2018年10月20日 16:49:11   作者:_YM雨蒙  
這篇文章主要介紹了使用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</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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • vue源碼學習之Object.defineProperty 對數組監(jiān)聽

    vue源碼學習之Object.defineProperty 對數組監(jiān)聽

    這篇文章主要介紹了vue源碼學習之Object.defineProperty 對數組監(jiān)聽,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Avue實現動態(tài)查詢與數據展示的示例代碼

    Avue實現動態(tài)查詢與數據展示的示例代碼

    Avue是一個基于Vue.js的前端框架,它是由阿里云開發(fā)的一款企業(yè)級UI組件庫,旨在提供一套全面、易用且高性能的界面解決方案本文介紹了Avue實現動態(tài)查詢與數據展示的示例,需要的朋友可以參考下
    2024-08-08
  • 解決vue2使用腳手架配置prettier報錯prettier/prettier:context.getPhysicalFilename is not a function

    解決vue2使用腳手架配置prettier報錯prettier/prettier:context.getPhysical

    這篇文章主要介紹了解決vue2使用腳手架配置prettier報錯prettier/prettier:context.getPhysicalFilename is not a function問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 使用Vue實現簡單的信號和電池電量組件

    使用Vue實現簡單的信號和電池電量組件

    這篇文章主要為大家詳細介紹了如何使用Vue實現簡單的信號和電池電量組件效果,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2025-04-04
  • 使用Vue?Query實現高級數據獲取的示例詳解

    使用Vue?Query實現高級數據獲取的示例詳解

    構建現代大規(guī)模應用程序最具挑戰(zhàn)性的方面之一是數據獲取,這也是?Vue?Query?庫的用途所在,下面就跟隨小編一起學習一下如何利用Vue?Query實現高級數據獲取吧
    2023-08-08
  • 基于Vue.js的表格分頁組件

    基于Vue.js的表格分頁組件

    這篇文章主要為大家詳細介紹了基于Vue.js的表格分頁組件使用方法,了解了Vue.js的特點,感興趣的朋友可以參考一下
    2016-05-05
  • Vue聲明式導航與編程式導航示例分析講解

    Vue聲明式導航與編程式導航示例分析講解

    這篇文章主要介紹了Vue中聲明式導航與編程式導航,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2022-11-11
  • 基于element日歷組件實現簽卡記錄

    基于element日歷組件實現簽卡記錄

    這篇文章主要為大家詳細介紹了基于element日歷組件實現簽卡記錄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • vue3中使用sse最佳實踐,封裝工具詳解

    vue3中使用sse最佳實踐,封裝工具詳解

    這篇文章主要介紹了vue3中使用sse最佳實踐,封裝工具,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • vue+elementui實現動態(tài)控制表格列的顯示和隱藏

    vue+elementui實現動態(tài)控制表格列的顯示和隱藏

    這篇文章主要介紹了vue+elementui實現動態(tài)控制表格列的顯示和隱藏,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04

最新評論

麻阳| 孝感市| 新泰市| 永济市| 淄博市| 泾阳县| 宝山区| 齐河县| 闽清县| 双城市| 汾阳市| 礼泉县| 恩施市| 上饶县| 南乐县| 舒兰市| 景谷| 惠水县| 云南省| 翁源县| 武宣县| 渑池县| 库伦旗| 台江县| 五华县| 汾阳市| 衡阳县| 博野县| 博白县| 阿克苏市| 巩留县| 邻水| 本溪市| 乐陵市| 福海县| 搜索| 临海市| 云安县| 江北区| 南汇区| 项城市|