【发布时间】:2020-06-23 09:08:49
【问题描述】:
在js中创建函数时,一旦创建函数,它就会给我标题中所述的错误。它还说';'预期,但是,我找不到问题。该函数是“created()”,我故意将其留空,因为它一有它就会给出错误。
代码如下:
const app = new Vue({
el: '#app',
data: {
errors: [],
name: null,
age: null
},
methods:{
checkForm: function (e) {
if (this.name && this.age) {
console.log(this.name);
return true;
}
console.log(this.name);
async created() {
}
this.errors = [];
if (!this.name) {
this.errors.push('Name required.');
}
if (!this.age) {
this.errors.push('Age required.');
}
e.preventDefault();
}
}
})
【问题讨论】:
-
async created() {}是做什么的?语法无效 -
async created() { }->async function created() { }或完全删除。 -
我整理出来了。这是我在浏览器中的新错误:CORS 策略已阻止 from origin 'null':请求的资源上不存在 'Access-Control-Allow-Origin' 标头。如果不透明的响应满足您的需求,请将请求的模式设置为“no-cors”以获取禁用 CORS 的资源。有什么帮助吗?
标签: javascript node.js vue.js