vuejs怎么修改背景色

vuejs修改背景色的方法:1、在index.html中引入公用的css样式;2、通过添加“beforeCreate () {…}”代码修改单个组件的背景色即可。

vuejs怎么修改背景色

本文操作环境:windows7系统、vue2.5.17版、Dell G3电脑。

vuejs怎么修改背景色?

Vue实现背景更换颜色操作

如下所示:

立即学习“前端免费学习笔记(深入)”;

vuejs怎么修改背景色

nbsp;html>.page{list-style: none;}.page>li{float: left;margin-left: 10px;}.page>li>a{text-decoration: none;}.active{color: red;text-decoration: display;}p{width: 500px;height: 500px;}

登录后复制 上一页 {{n}}下一页 var exampleData={//msg:”Hello Vue”,bgCol:”#DB8623FF”,totalPage:10,activeNum:3,}var app = new Vue({el:'#app',data:exampleData,methods:{decrease:function(){this.activeNum==1?'':this.activeNum-=1;this.bgCol=this.getRandom();},increase:function(){this.activeNum==10?'':this.activeNum+=1;this.bgCol=this.getRandom();},getRandom:function(){var r=Math.floor(Math.random()*256);var g=Math.floor(Math.random()*256);var b=Math.floor(Math.random()*256);var a=Math.random().toFixed(1);return `rgba(${r},${g},${b},${a})`}}})

vuejs怎么修改背景色

nbsp;html>  自定义指令实现随机背景   #app{  width: 999px;  height: 999px;  }  

自定义指令

 

 

  

    var exampleData = { myBgColor: "#5FCA34", }; new Vue({ el: "#app", data: exampleData, methods:{ getRandom:function(){var r=Math.floor(Math.random()*256);var g=Math.floor(Math.random()*256);var b=Math.floor(Math.random()*256);var a=Math.random().toFixed(1);return `rgba(${r},${g},${b},${b})` } }, directives: { changeBackgroundColor: { bind: function(el, bindings) { //el:指定绑定dom元素 h3dom对象 //bindings:自定义指令对象 //v-change-background-color="myBgColor" //bindings.value;=="#ff0000"var r=Math.floor(Math.random()*256);var g=Math.floor(Math.random()*256);var b=Math.floor(Math.random()*256);var a=Math.random().toFixed(1); el.style.backgroundColor =`rgba(${r},${g},${b},${a})`; console.log("绑定成功"); }, update: function(el, bindings) { console.log('已更新数据'); var r=Math.floor(Math.random()*256);var g=Math.floor(Math.random()*256);var b=Math.floor(Math.random()*256);var a=Math.random().toFixed(1); el.style.background = `rgba(${r},${g},${b},${a})` }, //更新数据 } } });

登录后复制

补充知识:vue统一设置了背景色,单独改变某一页的背景色

有时我们会遇到单独改变某个组件的背景填充色,而我们已经在index.html中引入了公用的css样式(body中设置了背景色),由于单个组件没有body标签,于是要修改单个组件的背景色只需添加如下代码即可。

beforeCreate () { document.querySelector('body').setAttribute('style', 'margin: 0 auto; width: 100%; max-width: 750px;min-width: 300px; background:#171b2a; overflow-x: hidden;height: 100%;');}

登录后复制

推荐学习:《vue教程》

以上就是vuejs怎么修改背景色的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3019561.html

(0)
上一篇 2025年3月13日 05:28:59
下一篇 2025年2月27日 02:12:54

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • vuejs怎么设置title

    vuejs设置title的方法:1、通过npm install安装“vue-wechat-title”;2、在main.js中引入“vue-wechat-title”;3、在index.js中给每个路由添加title即可。 本文操作环境:w…

    2025年3月13日
    200
  • vuejs中项目名怎么更改

    更改方法:1、打开项目根目录下“package.json”文件,将“name”项的值改成新的项目名;2、删除“node_modules”文件夹;3、在终端中进入项目文件夹,执行“npm install”和“npm run dev”命令即可。…

    2025年3月13日
    200
  • vuejs怎么引入css

    vuejs引入css的方法:1、在“app.vue”中的“”下直接引入对应的路径;2、将“@import”改成“”引入外部样式。 本文操作环境:Windows7系统、vue2.9.6版,DELL G3电脑。 vue.js引入外部CSS样式?…

    2025年3月13日
    200
  • vuejs怎么将毫秒转成日期

    vuejs将毫秒转成日期的方法:1、定义过滤器“filters.js”;2、在所用之处引入“filters.js”;3、通过“formatDate(data,’yyyy-MM-dd’);”进行转换即可。 本文操作环境…

    2025年3月13日 编程技术
    200
  • vuejs中axios用法是什么

    vuejs中axios的使用方法:1、安装axios;2、在main.js页面引用axios;3、通过“created(){this.$axios({method:’post’,url:’api&#821…

    2025年3月13日
    200
  • vuejs slot 怎么使用

    vuejs slot的使用方法:1、在子组件内放一些DOM;2、通过slot实现显示或者隐藏DOM,代码如“new Vue({el: “#app”,data: {},components:{children:{&#8…

    2025年3月13日 编程技术
    200
  • vuejs怎么改变css

    vuejs改变css的方法:1、使用“v-bind:class”或者“v-bind:style”指令修改css样式;2、直接通过操作dom来对css样式进行更改。 本文操作环境:Windows7系统、vue2.9.6版,DELL G3电脑。…

    2025年3月13日
    200
  • vuejs和vue的区别是什么

    vuejs和vue没有区别,vue只是vuejs的简称;而vuejs就是一套用于构建用户界面的渐进式JavaScript框架;与其它大型框架不同的是,Vue被设计为可以自底向上逐层应用。 本文操作环境:Windows7系统、vue2.9.6…

    2025年3月13日
    200
  • vuejs怎么隐藏当前元素

    vuejs隐藏当前元素的实现方法:1、在页面挂载完后,监听全局点击事件;2、获取当前点击的元素,根据需求获取当前元素本身的属性;3、判断当前点击元素与要隐藏的元素是否相同;4、当前点击元素与要隐藏的元素不相同则隐藏。 本文操作环境:Wind…

    2025年3月13日 编程技术
    200
  • vuejs怎么实现聊天界面

    vuejs实现聊天界面的方法:1、通过执行“npm install”安装dependencies;2、通过“scrollLoader.vue”实现滚动加载数据;3、修改main.js;4、设置App.vue中的参数即可。 本文操作环境:Wi…

    2025年3月13日
    200

发表回复

登录后才能评论