vue-cli按照库模式构建vue组件,html标签类名和css样式类名不一致的问题

node版本: v16.8.0
npm版本:7.21.0
Vue CLI v4.5.15
❯ Default ([Vue 2] babel, eslint)

  1. 创建一个vue组件

    <template>
    <div>
     <date-picker v-model="currentValue" :type="type"></date-picker>
    </div>
    </template>
    <script>
    import DatePicker from 'vue2-datepicker';
    import 'vue2-datepicker/index.css';
    import 'vue2-datepicker/locale/zh-cn';
    
    export default {
     props: {
       value: {
         type: String,
         default: function() {
           return ""
         }
       },
       type: {
         type: String,
         default: function() {
           return "datetime"
         }
       },
     },
     components: { DatePicker },
     data() {
       return {
         currentValue: this.value
       }
     },
     watch: {
       value(newValue) {
         this.currentValue = newValue
       },
       currentValue(newValue) {
         this.$emit('input', newValue)
         this.$emit('change', newValue)
       }
     }
    }
    </script>
  2. 构建

    vue-cli-service build --dest 'dist/datepicker' --target lib --name vlibDatePicker 'src/components/DatePicker.vue'
  3. 生成文件

vue-cli按照库模式构建vue组件,html标签类名和css样式类名不一致的问题

  1. 访问demo.html发现样式有问题

vue-cli按照库模式构建vue组件,html标签类名和css样式类名不一致的问题

  1. 原因是html标签的class没有加上hash,但是css文件类名却加上了hash

vue-cli按照库模式构建vue组件,html标签类名和css样式类名不一致的问题

按照官方文档操作,有哪位知道问题出在什么地方么?或者是某些配置没有设置好?

讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!