Blogger Information
Blog 250
fans 3
comment 0
visits 321872
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue自学:v-bind的对象写法,用对象绑定class
梁凯达的博客
Original
1178 people have browsed it

<!DOCTYPE html>

<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Document</title>
<style type="text/css">
.active{
color: red;
}
</style>
</head>
<body>
<div id="app">
<h1 v-bind:class="{active:isActive,line:isLine}">{{message}}</h1>
<button v-on:click="change">改变颜色</button>
</div>
</body>
<script type="text/javascript">
// v-on:click 绑定一个点击事件
// vi-on:click = ‘xx’ 绑定方式直接在后面增加一个方法名称即可,不用xx()
// 设计原理是给h1初始化的加上两个class 属性,分别是 active 和 line,通过取反的方式删除掉一个isActive值,变成 false
//class = {} 这个是属性的对象写法
//对象写法中,通常以 {键:值,键:值},对象写法在vue和日常使用中比较常用
//methods,是Vue的方法挂载方式
//在methods中,方法的写法为 function:function(){},而不是传统的JS写法
//
let app = new Vue({
el:’#app’,
data:{
message:’echo a red word’,
isActive:true,
isLine:true
},
methods:{
change:function(){
this.isActive = !this.isActive;
}
}
})
</script>
</html>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post