亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

在.vue組件中怎么實現單擊元素后改變該元素的樣式啊

在.vue組件中怎么實現單擊元素后改變該元素的樣式啊

正在回答

3 回答

style可以動態綁定,樣式class也可以動態綁定。

:style='thisStyle' ?:class="thisClass"

點擊的時候去改thisStyle或者 thisClass

0 回復 有任何疑惑可以回復我~

<style type="text/css">

.change{

width: 100px;

height: 100px;

background-color: red;

text-align: center;

line-height: 100px;

font-size: 40px;

color: white;

}

.changs{

width: 200px;

height: 200px;

background-color: blue;

text-align: center;

line-height: 100px;

font-size: 40px;

color: white;

}

</style>

<body>

? ? ? ? <div id="demo">

? ? ? ? <ones :class='[styles]'></ones>

? ? ? ? <button v-on:click='doIt'>點擊</button>

? ? ? ? </div>

<script type="text/javascript">

? ? ? ? ?var one={

? ? ? ? ? template:'<div>呵呵</div>'

? ? ? ? ?};

? ? ? ? ?new Vue({

? ? ? ? ? el:'#demo',

? ? ? ? ? data:{

? ? ? ? ? isTrue:true,

? ? ? ? ? styles:'change'

? ? ? ? ? },

? ? ? ? ? ? components:{

? ? ? ? ? ? 'ones':one

? ? ? ? ? ? },

? ? ? ? ? ? methods:{

? ? ? ? ? ? doIt:function(){

? ? ? ? ? ? this.styles='changs'

? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ?})

</script>

</body>


1 回復 有任何疑惑可以回復我~

思路:元素綁定onclick事件,通過onclick實現變量的賦值,樣式綁定變量即可

2 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
vue.js入門基礎
  • 參與學習       209639    人
  • 解答問題       715    個

本門為vuejs入門教程,詳細的講解加實戰,可以幫你進入vuejs的大門

進入課程

在.vue組件中怎么實現單擊元素后改變該元素的樣式啊

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號