亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

onToggleFinished方法中修改的是參數isFinished值,為什么會改變data里面items中的值呢?

http://img1.sycdn.imooc.com//5aa1f59c0001294e05780187.jpg

http://img1.sycdn.imooc.com//5aa1f59d0001d23e03970273.jpg

<template>

?<div id="app">

? ?<h1>{{ title }}</h1>

? ?<label for="newItem">

? ? ?<span>新建項目</span>

? ?</label>

? ?<input type="text" id="newItem"

? ? ? ? ? v-model="newItem" placeholder="請輸入新的項目名稱"

? ? ? ? ? v-on:keyup.enter="onAddNewItem()" >

? ?<button @click="onAddNewItem()">新增</button>

? ?<br />

? ?<h3>{{newItem}}</h3>

? ?<div>

? ? ?<ul>

? ? ? ?<li type="none"

? ? ? ? ? ?v-for="item in items" ?

? ? ? ? ? ?v-bind:class="[liClass, {'finished':item.isFinished}]"

? ? ? ? ? ?v-on:click="onToggleFinished(item)" >

? ? ? ? ?{{ item.label }}

? ? ? ?</li>

? ? ?</ul>

? ?</div>

?</div>

</template>


<script>


export default {

?data: function () {

? ?return {

? ? ?title: 'This is a todo list.',

? ? ?items: [

? ? ? ?{

? ? ? ? ?label: 'coding',

? ? ? ? ?isFinished: false

? ? ? ?},

? ? ? ?{

? ? ? ? ?label: 'running',

? ? ? ? ?isFinished: true

? ? ? ?}

? ? ?],

? ? ?liClass: 'isLiClass',

? ? ?newItem: ''

? ?};

?},

?methods: {

? ?onToggleFinished: function (item) {

? ? ? ?item.isFinished = !item.isFinished;

? ?},

? ?onAddNewItem: function () {

? ? ?// alert('新增項目中......');

? ? ?console.log(this.newItem);

? ? ?this.items.push({

? ? ? ?label: this.newItem,

? ? ? ?isFinished: false

? ? ?});

? ? ?this.newItem = '';

? ?}

?}


}

</script>


<style>


?.finished {

? ?text-decoration: underline;

?}


?html {

? ?height: 100%;

?}


?body {

? ?display: flex;

? ?flex-direction: row;

? ?align-items: center;

? ?justify-content: center;

? ?height: 100%;

?}


?#app {

? ?font-family: 'Avenir', Helvetica, Arial, sans-serif;

? ?-webkit-font-smoothing: antialiased;

? ?-moz-osx-font-smoothing: grayscale;

? ?text-align: center;

? ?color: #2c3e50;

? ?margin-top: 60px;

?}

</style>



正在回答

1 回答

你data里面的li調用了這個方法啊

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
vue.js入門基礎
  • 參與學習       209639    人
  • 解答問題       715    個

本門為vuejs入門教程,詳細的講解加實戰,可以幫你進入vuejs的大門

進入課程

onToggleFinished方法中修改的是參數isFinished值,為什么會改變data里面items中的值呢?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號