亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時(shí)間:2018年10月20日 16:49:11   作者:_YM雨蒙  
這篇文章主要介紹了使用Vue做一個(gè)簡(jiǎn)單的todo應(yīng)用的三種方式的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

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. 全局組件注冊(cè)

<!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>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

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

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

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

    vue輕量級(jí)框架無(wú)法獲取到vue對(duì)象解決方法

    這篇文章主要介紹了vue輕量級(jí)框架無(wú)法獲取到vue對(duì)象解決方法相關(guān)知識(shí)點(diǎn),有需要的讀者們跟著學(xué)習(xí)下。
    2019-05-05
  • 一款移動(dòng)優(yōu)先的Solid.js路由solid router stack使用詳解

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

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

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

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

    Vscode關(guān)閉Eslint語(yǔ)法檢查的多種方式(保證有效)

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

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

    這篇文章主要介紹了vue.js中使用微信掃一掃解決invalid signature問(wèn)題(推薦),本文通過(guò)實(shí)例代碼給出解決方法,代碼簡(jiǎn)單易懂非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    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實(shí)現(xiàn)中文A-Z排序的方法

    vue.js或js實(shí)現(xiàn)中文A-Z排序的方法

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

    vue3動(dòng)態(tài)路由刷新后空白或者404問(wèn)題的解決

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

    解決Vue?input輸入框卡死的問(wèn)題

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

最新評(píng)論