1.问题就是
你先定义一个js 然后里面写
export default {
init: function () {
this.handleAddListener(‘load’, function () {
console.log(“export 中的方法被调用了”)
})
},
handleAddListener: function (type, fn) {
if (window.addEventListener) {
window.addEventListener(type, fn)
} else {
window.attachEvent(‘on’ + type, fn)
}
}
}
然后在html 引入 你会发现, Uncaught SyntaxError: Unexpected token export
这里说明 你引入的是一个模块 所以
没完事, 然后你在看
Access to script at ‘file:///F:/project/test/a.js’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
哇靠神马东西, 这个文件跨域。 解决的办法
你这地址? 是不是很奇怪? 所以 全安装
npm i anywhere -g
安装之后 来到html anywhere
点那个html