国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答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
主站蜘蛛池模板: 国产69精品久久久久999 | 亚洲另类中文字幕 | 欧美爱爱网站 | 在线日韩视频 | 国产在线观看第一页 | 欧美一区二区免费 | 久久大陆 | 国产二区视频 | 日韩专区在线 | 免费一区二区 | 国产高清精品久久久久久久 | 欧美日韩一区二区三区在线播放 | 久久99国产精品成人欧美 | 91在线 | 欧美: | 一级毛片视频免费 | 亚洲国产一区二区三区精品 | 亚洲国产成人精品区 | 亚洲欧美日韩高清综合678 | 成人毛片一区二区三区 | 一区国严二区亚洲三区 | 日本v片免费一区二区三区 欧洲精品欧美精品 | 国产日产高清欧美一区二区三区 | 精品免费久久久久国产一区 | 精品一区二区三区免费毛片爱 | 在线国产一区二区三区 | 九九爱精品视频 | 国产欧美日韩亚洲 | 免费国产一区 | 久久婷婷色一区二区三区 | 国产精品一区二区久久不卡 | 国产成人精品视频一区二区不卡 | 成人欧美一区二区三区在线 | 91麻精品国产91久久久久 | 免费观看国产精品 | 精品国产一区二区三区免费看 | 伊人色综合一区二区三区 | 欧美色图亚洲激情 | 欧美中文娱乐网 | 日韩一区二区三区不卡 | 国产毛片高清 | 国产精品99久久久 |