In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to solve the function () { [native code] } error in vue". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to solve the function () { [native code] } error in vue"!
{[native code]}{ [native code] }}{ [native code] }}}{[native code] }}}{{{
Console Output Error:
[Vue warn]: Unknown custom element: - did you register the component correctly?
For recursive components, make sure to provide the "name" option.
Page prompt:
function () { [native code] }, cannot appear what we want
页面代码:
Title {{currentTime1}} var vm=new Vue({ el:"#vue", data:{ message:"hello world" }, methods:{ currentTime1: function () { return Date.now();//返回当前时间戳 } } });
综上错误,究其原因就是新人对"计算属性":computed和"事件处理":methods傻傻分不清楚。根据官方文档总结如下:
对于任何复杂逻辑,你都应当使用计算属性。其余可以使用methods处理。
所以,下次如果再出现function () { [native code] },请使用对应的方法获取值。
这里的methods方法就应该使用currentTime1()调用,计算属性computed就应该使用currentTime2调用。
完整methods方法和计算属性对比运行代码如下:
Title {{currentTime1()}} {{currentTime2}} var vm=new Vue({ el:"#vue", data:{ message:"hello world" }, methods:{ currentTime1: function () { return Date.now();//返回当前时间戳 } }, computed:{ //存在缓存,建议不经常的变化的在次操作 currentTime2:function () { return Date.now(); } } });
页面效果:
vue使用过程中遇到的bug及解决1.用event.target操作当前元素出现bug
改为用event.currentTarget。
2.data数据更新之后渲染页面是异步的
所以要在$nextTick里面,DOM元素更新之后再操作DOM
3.v-cloak解决网络不好时页面显示双花括号{{}}问题 {{ item.title }} [v-cloak] { display: none; }4.v-pre跳过组件和子组件的编译过程
比如{{ instead }}渲染出来的是{{ instead }}字符串,不会再js中找instead这个数据
5.element的navMenu导航菜单的index不能用数字
而要用字符串。
解决办法: :index = "index + ‘’" 转化成字符串
6.vue中main.js一引入sass文件就报错
提示路径找不到或者依赖找不到,是因为webpack.base.conf.js中
{ test: /\.scss$/, loaders: ["style", "css", "sass"] }
重复配了,把它删掉就好了(新版的vue-cli默认配置了这个)
7.所有的v-if最好都加上key
否则因为相同标签元素复用会导致意想不到的bug
到此,相信大家对"vue中出现function () { [native code] }错误怎么解决"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.