• 技术文章 >web前端 >Vue.js

    vue.js怎么改变样式

    coldplay.xixicoldplay.xixi2020-11-30 15:39:08原创943

    vue.js改变样式的方法:首先给元素定义ref属性;然后通过js方法修改元素的样式,代码为【'background-color:#1F2429;width:66px'】;最后修改单一样式时可直接使用样式名称。

    本教程操作环境:windows7系统、vue2.9.6版,该方法适用于所有品牌电脑。

    【相关文章推荐:vue.js

    vue.js改变样式的方法:

    1、给元素定义ref属性

     <el-button ref="btnClick" class="list_button" " @click="openClose"></el-button>

    2、通过js 方法修改元素的样式 修改较多样式时可使用cssText

    function openClose() {
            this.isCollapse = !this.isCollapse
     
            if (this.isCollapse) {
                this.$refs.btnClick.$el.style.cssText =
                    'background-color:#1F2429;width:66px';
               
            } else {
                this.$refs.btnClick.$el.style.cssText =
                    'background-color:#1F2429;width:140px';
            }
        }

    3、修改单一样式时可直接使用样式名称

    function openClose() {
            this.isCollapse = !this.isCollapse
     
            if (this.isCollapse) {
                this.$refs.btnClick.$el.style.color = 'red';
               
            } else {
                this.$refs.btnClick.$el.style.color = 'blue';
            }
        }

    相关学习推荐:javascript学习教程

    以上就是vue.js怎么改变样式的详细内容,更多请关注php中文网其它相关文章!

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:vue.js 样式
    上一篇:vue脚手架如何导入jquery第三方插件 下一篇:vue.js怎样引入css样式
    大前端线上培训班

    相关文章推荐

    • 在html元素中设置css样式的方式是什么• Vue中的样式绑定详解• jquery怎么去除css样式?• react组件添加样式的方法

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网