一个关于vue+element-ui打包样式污染的问题

 因为是二次开发得到项目有一些莫名其妙的问题找不到原因,上网搜了很久都是有关避免写的样式污染其他页面  没有我遇到的这种情况

一开始是使用的行内样式,因为行内的权重比较高,但是打包上线之后通过控制台发现这个input的样式是    .el-select>.el-input:width:140px;   这就很恶心

            <el-col :span="12">
              <el-form-item label="类型" prop="wellType">
                <el-select
                  styel="width:220px"
                  v-model="form.wellType"
                  placeholder="选择类型"
                  :filterable="true"
                  :clearable="true"
                >
                  <el-option
                    v-for="(item, index) in TypeList"
                    :label="item.name"
                    :value="item.name"
                    :key="index"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

 再后来就想着给他加一个单独的类名再进行样式设置

            <el-col :span="12">
              <el-form-item label="类型" prop="wellType">
                <el-select
                  class="inpp"
                  v-model="form.wellType"
                  placeholder="选择类型"
                  :filterable="true"
                  :clearable="true"
                >
                  <el-option
                    v-for="(item, index) in TypeList"
                    :label="item.name"
                    :value="item.name"
                    :key="index"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

<style>
.inpp>.el-input__inner{
  width: 220px !important;
}
.inpp>.el-input{
  width: 220px !important;
}
</style>

 因为再控制台看到的需要改变样式的标签为el-input 和 el-input_inner  还有就是前面的自定义类名可以有效的防止样式污染,   因为没有找到污染这个标签的污染源   我怕权重不够  就又给他加了一个 !important  

之后就是打包上线了   上线之后发现问题已经解决,

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue中引入Element-ui,你可以按照以下两种方法之一进行操作: 方法一:全局引入 在src下的main.js文件中,你可以引入ElementUI组件,并在Vue实例中使用Vue.use(ElementUI)来全局注入Element-ui。还需要引入Element-ui样式文件,可以使用import 'element-ui/lib/theme-chalk/index.css'.以下是示例代码: ``` import Vue from 'vue' import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; import App from './App.vue' Vue.config.productionTip = false Vue.use(ElementUI); new Vue({ render: h => h(App), }).$mount('#app') ``` 方法二:按需引入 在src下的main.js文件中,你可以按需引入Element-ui所需的组件,并使用Vue.use(ComponentName)来按需注入需要使用的组件。同样需要引入Element-ui样式文件。以下是示例代码: ``` import Vue from 'vue' import { Button, Radio } from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; import App from './App.vue' Vue.config.productionTip = false Vue.use(Button); Vue.use(Radio); new Vue({ render: h => h(App), }).$mount('#app') ``` 需要注意的是,按需引入时,你需要指定你要使用的组件,例如Button和Radio。这样可以减少打包后的文件大小。 而在bable.config.js中,你可以添加Element-ui的插件配置,以自动按需引入Element-ui组件的样式。以下是示例代码: ``` "plugins": [ [ "component", { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" } ] ] ``` 这样就可以根据需要灵活引入和使用Element-ui组件了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [vue引入Element-ui](https://blog.csdn.net/m0_51459514/article/details/123655142)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值