JSFiddle - React, Tailwind, and code Playground
by IanZhong
HTML
<html>
<header>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</header>
<body>
<div id="app">
<div class="box" :style="style"></div>
<button @click="changeStyle">changeStyle</button>
</div>
</body>
</html>
CSS
.box {
width: 100px;
height: 100px;
}
JavaScript
new Vue({
el: '#app',
data: {
flag: true
},
computed: {
style() {
let styleA = {
borderBottom: '1px solid red',
borderRight: '1px solid red'
};
let styleB = {
border: '1px solid green',
borderRight: '1px solid red'
}
return this.flag ? styleA : styleB
}
},
methods: {
changeStyle() {
this.flag = !this.flag;
}
}
})