Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

本地用script引用vue,Vue对象没有挂载到window上

在head用script引用本地同级目录vue.js文件(文件来源Vue官网)。
console.log(Vue) //报错:显示未定义

但是从CDN引用没有报错

为啥上边的有报错?
code.png
c.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

很奇怪。讲道理是不会有这个问题的。

而且可以看到下面的 vue 初始化。

发布一下?提供个网络地址。


留一下正确答案:因为使用 parcel 执行构建过程,parcel index.html,所以 vue.js 走到了模块化开发(没有全局绑定 Vue)。

所以改成引入 index.js。然后 index.js 里面 import Vue from './vue'; 就可以快乐的使用了。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...