惊慌失措脸,我做错什么了???这时候,我们不妨看看代码吧:
created() {
displayInfo({
name: "CAT",
age: 22
});
},
methods: {
displayInfo(args) {
var output = "";
if (typeof args.name == "string") {
output += "NAME:" + args.name + "/n";
}
if (typeof args.age == "number") {
output += "AGE:" + args.age + "/n";
}
alert(output);
}
}
没错,就是这么简单的几行代码也能出错。(赏:鹤顶红)
好了,回归正题:在created中调用methods中的方法,要加this关键字!!!,代码如下:
created() {
this.displayInfo({
name: "CAT",
age: 22
});
}
不要气馁哦,再努力一次吧!!!