标签绑定class属性:v-bind:class="{changeColor: true}"
注意里面的写法是对象的形式
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Vue.js</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<!-- vue-app是根容器 -->
<div id="vue-app">
<h1> 动态 CSS Class</h1>
<h2>实例 1</h2>
<div v-on:click="changeColor=!changeColor" v-bind:class="{changeColor: changeColor}">
<span> changeColor </span>
</div>
<h2>实例 2</h2>
<button v-on:click="changeColor=!changeColor"> change color