在vue中使用,需要先npm install snapsvg將其引入,其次需要引入npm install imports-loader,然後在使用時會碰上巨坑Uncaught TypeError: Cannot read property ‘on’ of undefined,這時我們就需要在使用時對其進行一定的處理如下:
import Snap from 'imports-loader?this=>window,fix=>module.exports=0!snapsvg/dist/snap.svg.js'
這樣引入即可解決。或者通過修改webpack配置如下:
module.exports = {
module: {
...
loaders: [
{
test: require.resolve('snapsvg'),
loader: 'imports-loader?this=>window,fix=>module.exports=0'
}
]
}
};