1.问题描述:
vue引用layer的时候
import layer from "layui-layer"
运行报了下面的错误:
解决方法:
Importing an object into Vue's app JS doesn't automatically produce that object for use by other components.
There are at least two ways to do this (though I recommend avoiding all this and just importing jQuery
in the components that need it):
Option 1: Vue.prototype
In your app JS, add jQuery to the Vue
prototype after you import it, which will make it accessible to every component using the syntax this.jQuery
:
Vue.prototype.jQuery = jQuery
Option 2: window
object
Alternatively, you could add it to the window object after importing and use it like window.jQuery
:
window.jQuery = jQuery
Option 3: Individual imports
It's probably more readable/maintainable to simply import it in components that use it:
import jQuery from 'jquery'
and then you can use it with the syntax in your example.