欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用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-cli3中配置alias和打包加hash值操作

    vue-cli3中配置alias和打包加hash值操作

    這篇文章主要介紹了vue-cli3中配置alias和打包加hash值操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue輕量級框架無法獲取到vue對象解決方法

    vue輕量級框架無法獲取到vue對象解決方法

    這篇文章主要介紹了vue輕量級框架無法獲取到vue對象解決方法相關知識點,有需要的讀者們跟著學習下。
    2019-05-05
  • 一款移動優(yōu)先的Solid.js路由solid router stack使用詳解

    一款移動優(yōu)先的Solid.js路由solid router stack使用詳解

    這篇文章主要為大家介紹了一款移動優(yōu)先的Solid.js路由solid router stack使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • vue3中?provide?和?inject?用法及原理

    vue3中?provide?和?inject?用法及原理

    這篇文章主要介紹vue3中?provide?和?inject?用法及原理,provide?和?inject可以?解決多次組件傳遞數據的問題,下面文章是具體的用法和實現原理,具有一定的參考價值,需要的朋友可以參考一下,希望對大家有所幫助
    2021-11-11
  • Vscode關閉Eslint語法檢查的多種方式(保證有效)

    Vscode關閉Eslint語法檢查的多種方式(保證有效)

    eslint是一個JavaScript的校驗插件,通常用來校驗語法或代碼的書寫風格,下面這篇文章主要給大家介紹了關于Vscode關閉Eslint語法檢查的多種方式,文章通過圖文介紹的非常詳細,需要的朋友可以參考下
    2022-07-07
  • vue.js中使用微信掃一掃解決invalid signature問題(完美解決)

    vue.js中使用微信掃一掃解決invalid signature問題(完美解決)

    這篇文章主要介紹了vue.js中使用微信掃一掃解決invalid signature問題(推薦),本文通過實例代碼給出解決方法,代碼簡單易懂非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • 使用vue-cli+webpack搭建vue開發(fā)環(huán)境的方法

    使用vue-cli+webpack搭建vue開發(fā)環(huán)境的方法

    這篇文章主要介紹了使用vue-cli+webpack搭建vue開發(fā)環(huán)境的方法,需要的朋友可以參考下
    2017-12-12
  • vue.js或js實現中文A-Z排序的方法

    vue.js或js實現中文A-Z排序的方法

    下面小編就為大家分享一篇vue.js或js實現中文A-Z排序的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • vue3動態(tài)路由刷新后空白或者404問題的解決

    vue3動態(tài)路由刷新后空白或者404問題的解決

    在vue項目中采用動態(tài)添加路由的方式,第一次進入頁面會正常顯示,但是點擊刷新頁面后會導致頁面空白,所以下面這篇文章主要給大家介紹了關于vue3動態(tài)路由刷新后空白或者404問題的解決方法,需要的朋友可以參考下
    2022-07-07
  • 解決Vue?input輸入框卡死的問題

    解決Vue?input輸入框卡死的問題

    這篇文章主要介紹了解決Vue?input輸入框卡死的問題,文中同時給大家提到了Vue-element中el-input輸入卡頓問題及解決方法,本文結合示例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2022-09-09

最新評論