【问题标题】:How to change style of background color using Vue.js only如何仅使用 Vue.js 更改背景颜色的样式
【发布时间】:2019-04-13 06:20:08
【问题描述】:
import Vue from 'vue'
import App from './App'
import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'




Vue.config.productionTip = false
Vue.use(BootstrapVue);


/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>'
})

<template>
  <div id="app">
    <webpage></webpage>
  </div>
</template>

<script>

import webpage from "./components/webpage"


export default {
  name: 'app',
  components : {
    webpage
  }
}
</script>

<style>

</style> 

我尝试使用命令v-bind:style='{backgroundColor : color} 使用 vue 绑定样式更改元素的背景颜色 但它不是全高,即使我试图删除 CSS 上 body 元素的边距和填充,但仍然无法正常工作,正如你在图片中看到的那样,谢谢

#wrapper{
   
    width: 650px  ;
    height: auto;
    background-color: rgb(198, 241, 200);
    margin: 0 auto;
    margin-top: 200px;
    border-radius: 10px;
}
html, 
body {
    margin: 0;
    padding: 0;
    background-color:rgb(250, 28, 65);
}

【问题讨论】:

    标签: css vue.js vuejs2 vue-component bootstrap-vue


    【解决方案1】:

    将您的元素绑定到样式对象,如下所示:

      <div :style="myStyle" id="wrapper">
    

    在您的数据对象中:

         data(){
           return{
             myStyle:{
                backgroundColor:"#16a085" 
                }
              ...
               }
             }
    

    您可以检查this 我在您的 css 规则中进行了几处更改而不会影响 Vue 逻辑

    【讨论】:

      猜你喜欢
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多