先看代码,代码很简单,没有任何问题,但是运行的时候就出问题了,看截图。
(function()
{
Vue.component("test",
{
template:"<h1>{{hello}}</h1>",
data:function()
{
return
{
hello:"你好"
};
}
});
})();

网上看查了就,就是没发现任何问题,复制粘贴的代码也能运行成功,自己写就是不行。我大学是软件工程的学的编程语言很多,所以C#代码风格保留了下来,就是这个风格导致的错误。修正代码:
(function()
{
Vue.component("test",
{
template:"<h1>{{hello}}</h1>",
data:function()
{
return {
hello:"你好"
};
}
});
})();
发现有什么不一样吗?
return {
hello:"你好"
};
//区别,下面的代码返回undefined
return
{
hello:"你好"
};

做C#的朋友注意一下,坑
网友评论