是否可以将内联样式与vue.js绑定?

编程入门 行业动态 更新时间:2024-10-28 04:27:23
本文介绍了是否可以将内联样式与vue.js绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我很好奇,是否可以在Vue.js中绑定内联样式?我对类绑定很熟悉,但是如果有时出于某种原因想要内联绑定样式语句,又有可能像对类一样进行绑定吗?

I am curious, is it possible to bind the inline style in Vue.js? I'm familiar with class binding but what if sometimes for some reason you want to bind a style statement inline, is it possible to bind it like you do with class?

例如,

<template> <div> <h1 :style="{('background:red') : condition}"> Text </h1> <button @click='condition = true'>Click me</button> </div> </template> <script> export default { data(){ return { condition:false } } } </script>

在上面的示例中,我想在条件变为真时更改元素的背景.

In the example above I'd like to change the background of the element when the condition becomes true.

推荐答案

当然可以按照此处的描述进行操作: vuejs/v2/guide/class-and-style.html

Of course it is possible as described here: vuejs/v2/guide/class-and-style.html

<template> <div> <h1 v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"> Text </h1> <button @click='condition = true'>Click me</button> </div> </template> <script> export default { data(){ return { condition:false, activeColor: 'white', fontSize: 12 } } } </script>

更多推荐

是否可以将内联样式与vue.js绑定?

本文发布于:2023-11-24 19:27:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内联   绑定   样式   vue   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!