(學習VUE那些事)v-bind+v-for點選改變列表顏色
阿新 • • 發佈:2020-12-26
學習VUE記錄一些自己在VUE上面的點滴
下面展示一些 內聯程式碼片
。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VUE點選列表改變樣式</title>
</head>
<script src="js/vue.js"></script>
<!-- 引入vue.js檔案 -->
<style>
.form{
color:red
}
/* //設定 class名為form的樣式 */
</style>
<body>
<div id="app">
<!-- //先建立一個id為app的div. -->
<ul>
<li :class="{form : isform == index}" v-for = "(m,index) in mest" @click="click(index)">{{index}}--------{{m}} </li>
<!-- //繫結一個名為click的點選事件 -->
<!-- v-for遍歷的時候, 如果是物件的話,需要索引則需要3個變數。例如: v-for="(m,m2,index) in mest" -->
</ul>
</div>
</body>
<script>
var app = new Vue({
//new的Vue第一個字母要大寫
el:"#app",
data:{
mest:["1","2","3"],
//mest這個資料可以是資料或者物件。物件的格式:mest:{pos1:"post1",pos2:"psot2",pos3:"psot3"}
isform:false
},
methods:{
click:function(index){
this.isform = index
}
}
})
</script>
</html>
有什麼寫錯的地方請在留言上給我指正,不勝感激。