【发布时间】:2020-07-22 17:27:17
【问题描述】:
我已经使用 NPM 安装了几个库。
你必须加载文件才能在那里使用它。所有安装的库都在 node_modules 下
名称是这样的。
<script src="../node_modules/vue/dist/vue.js"></script>
我确定它在服务器上,我确定脚本标签的 URL 是正确的 我在脚本中收到以下错误,即使它是这样指定的
login.html:45 GET https://***/node_modules/vue/dist/vue.js net::ERR_ABORTED 404
我单独准备的js文件加载了,但是原来的vue.js没有加载,所以又报错了。
这就是我们试图用 VUE 做的事情。 我打算用Ajax创建一个SPA
/* eslint-disable no-console */
const vue = require("vue"); //I added it, but it's still not working.
const axios = require("axios"); //I added it, but it's still not working.
var app = new Vue({
el: "#app",
data: {
url: "https://*****",
user: "",
password: "",
res: ""
},
methods: {
login: function () {
axios.post(this.url, {
user: this.user,
password: this.password
})
.then(function (response) {
this.res = response.data.d;
if (this.res === true) {
//true
} else {
//failed
}
})
.catch(function (error) {
alert('System error');
});
}
}
})
【问题讨论】:
-
您使用的是哪个服务器框架?快递?
-
@mepley 不,这是一个 Windows 服务器。
-
将
Vue中您需要它的“v”大写,看看这是否有效。例如:const Vue = require("vue"); -
@mepley 如果我这样重写,仍然无法使用 Vue,我知道该怎么做吗?
标签: javascript html vue.js node-modules