課程
/前端開(kāi)發(fā)
/Vue.js
/vue2.5入門(mén)
點(diǎn)一下已經(jīng)發(fā)布的li,為li加一個(gè)樣式,增加刪除線表示完成
2018-11-02
源自:vue2.5入門(mén) 3-1
正在回答
提供一個(gè)思路:
在v-bind里面使用三目運(yùn)算符 判斷是否完成 完成添加完成的樣式 否則就是正常樣式
<div id="app">
<h1 v-html='title'></h1>
<input v-model='newItem' v-on:keyup.enter='addNewItem'>
<button @click="addNewItem">ADD</button>
<ul>
<li v-for="item in items" v-bind:class="[{finished:item.isFinished},item.color]" @click="finish(item)">{{item.label}}</li>
</ul> ?
</div>
<script>
new Vue{
el:'#app',
data(){
return{
title:'this is a todo list!',
items:
[
{
label:'code',
isFinished:true,
color:'red',
},
label:'run',
isFinished:false,
}
],
newItem:'',
methods:
finish:function (item)
item.isFinished=!item.isFinished
addNewItem:function ()
if(this.newItem!='')
this.items.push({
label:this.newItem,
})
this.newItem=''
</script>
<style>
#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;
.finished{
text-decoration: underline;
.red{
color: red;
</style>
點(diǎn)擊Li,增加underline,再點(diǎn)擊變?yōu)閚one
舉報(bào)
快速理解Vue編程理念上手Vue2.0開(kāi)發(fā)。
2 回答只在一個(gè)div里面添加了點(diǎn)擊事件,為什么所有msg都改變了
4 回答點(diǎn)擊li時(shí)如何在alert中顯示li的內(nèi)容
4 回答為什么每次點(diǎn)擊都是刪除最后一個(gè),而不是刪除點(diǎn)擊的那個(gè)li
1 回答怎么添加單擊事件就報(bào)錯(cuò)???
2 回答為什么同時(shí)3個(gè)包含content的標(biāo)簽,只有1個(gè)綁定了click事件,但是,點(diǎn)擊的時(shí)候3個(gè)同時(shí)觸發(fā)了點(diǎn)擊事件
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-11-07
提供一個(gè)思路:
在v-bind里面使用三目運(yùn)算符 判斷是否完成 完成添加完成的樣式 否則就是正常樣式
2018-11-07
<div id="app">
<h1 v-html='title'></h1>
<input v-model='newItem' v-on:keyup.enter='addNewItem'>
<button @click="addNewItem">ADD</button>
<ul>
<li v-for="item in items" v-bind:class="[{finished:item.isFinished},item.color]" @click="finish(item)">{{item.label}}</li>
</ul> ?
</div>
<script>
new Vue{
el:'#app',
data(){
return{
title:'this is a todo list!',
items:
[
{
label:'code',
isFinished:true,
color:'red',
},
{
label:'run',
isFinished:false,
color:'red',
}
],
newItem:'',
}
},
methods:
{
finish:function (item)
{
item.isFinished=!item.isFinished
},
addNewItem:function ()
{
if(this.newItem!='')
{
this.items.push({
label:this.newItem,
isFinished:false,
color:'red',
})
this.newItem=''
}
},
},
}
</script>
<style>
#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;
}
.finished{
text-decoration: underline;
}
.red{
color: red;
}
</style>
點(diǎn)擊Li,增加underline,再點(diǎn)擊變?yōu)閚one