javascript - Vue.js Import mixin 不在应用程序中导入

标签 javascript vue.js vuejs2 vue-component vue-mixin

The requested module './clienteMixin.js' does not provide an export named 'default'

混合

export const myMixin = {
    data() {
        return {
            loading: false,
        }
    }
}

Vue 应用

import myMixin from './clienteMixin.js'

var app = new Vue({
    delimiters: ['[[', ']]'],
    el: '#app',
    components:{},
    mixins: [myMixin],
    data() {
        return {
            
        }
    },
    methods: {
    
    },
    mounted () {
    
    }
});

最佳答案

首先更改您的导出以使用默认导出:

export default {
  data() {
    return {
      loading: false,
    }
  },
}

这将解决导入问题。如果你想让你的 mixin 成为 global mixin , 使用 Vue.mixin :

import myMixin from './clienteMixin.js'

Vue.mixin(myMixin);

const app = new Vue({
    delimiters: ['[[', ']]'],
    el: '#app',
    components:{},
    data() {
      return {
      }
    },
    methods: {
    },
    mounted () { 
    }
});

关于javascript - Vue.js Import mixin 不在应用程序中导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66113704/

相关文章:

javascript - 如何将 dropbox.js 与 OAuth 1 结合使用

javascript - 为什么 MDN 说 "Function.prototype cannot be modified"?

javascript - 在Vue中使用Axios Api发布数据

javascript - Vue - 如何使分页工作作为响应的一部分

vue.js - Bootstrap vue 表的动态分页

javascript - 文本溢出校正

javascript - chrome.tabs.query() 导致浏览器崩溃

node.js - 使用 puppeteer 生成 PDF 而不保存

javascript - Vueify + Elixir + 热加载 - 未捕获的类型错误 : Cannot read property 'indexOf' of undefined

javascript - 使用vuejs动态设置id标签