In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve style binding Vue, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
1. Style binding (class, style) 1.1 binding class
The fixed class name is written normally, and the class name that needs to be dynamically bound is bound by v-bind.
For example: class= "mood"
Here are some applicable scenarios:
1. Bind class style-string writing method, suitable for: the class name of the style is uncertain and needs to be specified dynamically
two。 Bind class style-scenarios used in array writing: the number of styles bound is uncertain and the name is uncertain
3. Binding class style-scene used for object writing: the number of bindings is determined, the name is also determined, and what is uncertain is whether the class name is used or not
.basic {width: 100px; height: 100px; border: 2px solid black;} .happy {width: 100px; height: 100px; border: 2px solid orange; background-color: palevioletred;} .sad {width: 100px; height: 100px Border: 2px solid black; background-color: silver;} .normal {width: 100px; height: 100px; border: 2px solid greenyellow; background-color: sandybrown;} .colors {border-radius: 20%;} .color {color: skyblue } .size {font-family: 'Microsoft Yahei'; font-size: 20px; font-weight: bold } {{name}} {{name}} {{name}} Vue.config.productionTip = false let vm = new Vue ({el:'# root', data: {name: "Hello,Vue!" Mood: "normal", classArr: ['outline','color','size'], classObj: {outline:true, color:true}} Methods: {random () {let arr = ["happy", "sad", "normal"] / / Math.floor: round down, Math.random (): 0-1 1 is not available this.mood = arr [Math.floor (Math.random () * 3)]}, remove () {this.classArr.shift ()} Change () {vm.classObj.color =! vm.classObj.color vm.classObj.outline =! vm.classObj.outline}) 1.2 bind style
For example:: style = "styleobj"
Hello, {{name}}! Vue.config.productionTip = false let vm = new Vue ({el:'# root', data: {name: "Vue", styleobj: {fontSize: 50 + "px", color: "red" Border:1+ "px" + "+" solid "+" + "black"}) these are all the contents of the article "how Vue implements style binding" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.