<script setup>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import HelloWorld from './components/HelloWorld.vue'
</script>
<template>
<!--动态指令,这相当于是class="d1",后面的d1其实也是变量 事件名称也可以是变量-->
<div v-bind:[attributeName]="d1"></div>
<!--id="d1"-->
<button @click="toggleColor">点击切换颜色</button>
<!--事件名称是变量 相当于@click-->
<button @[eventName]="toggleColor">点击切换颜色</button>
</template>
<script>
//命令式
//document.querySelector("h1").innerHTML="helloworld"
//声明式, 先声明出变量。
export default{
name:'App',
data(){
return{
attributeName:"class",
d1:"d1",
eventName:"click"
}
},
methods:{
toggleColor(){
this.attributeName="id"
}
}
}
</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;
}
#d1{
widows: 100px;
height: 100px;
background: yellow;
}
/*.d1 表示类名 */
.d1{
widows: 100px;
height: 100px;
background: green;
}
</style>
5. 模板语法,动态指令,v-bind
原创
©著作权归作者所有:来自51CTO博客作者我是数哥的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
十、v-bind 指令
&n
Vue -
Vue 常用指令 v-bind 绑定动态值
用于动态绑定一个或多个
vue.js 前端 javascript html css -
【Vue】—动态绑定v-bind
【Vue】—动态绑定v-bind
vue javascript html css 动态绑定 -
v-bind
点写 @v-bind是绑定熟悉 简写 :好 直接看代码上面的代
数组 数据中心 css