浅析vue component 组件使用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了浅析vue component 组件使用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1245字,纯文字阅读大概需要2分钟。
内容图文
![浅析vue component 组件使用](/upload/InfoBanner/zyjiaocheng/346/997a031a17944597b8628e1566e5fae5.jpg)
component 使用
component的注册
1.全局注册
使用用Vue.component('componentName',{template:'<div class="tem1">hello world</div>'})在初始化实例之前。
componentName自定义名称
在实例声明的作用域下中使用<componentName></componentName> 成功渲染效果就是 '<div class="tem1">hello world</div>
Vue.component('my-component',{ template:'<div class="tem1">hello world</div>' }
组件中的数据使用
component不能使用实例的data ,但是可以在component 使用data 声明变量,data的使用只能使用函数形式
Vue.component('my-component',{ template:'<div class="tem1">hello world {{comdata}}</div>', data:function(){return {comdata:'hehe'}} });
2.局部主持
在实例化的new Vue 中设置components
var app=new Vue({ el:'#app', components:{'example':{template:'<div>children template</div>'}} })
组件中的数据使用
var app=new Vue({ el:'#app', data:{num:220}, components:{ 'example':{ template:'<div>children template{{mydata}}</div>', data:function(){return {mydata:' mydata=data'};} } } })
注意:组件不能使用实例的data:{num:220}的参数会报错
组件中同样支持methods、computed等其他属性 不会冲突保持相对的独立
这时候就必须考虑不同组件的数据通信问题
vue js总结来说通过props down events up 来传输数据
给父级调用数据使用props声明,给子集调用使用events来声明
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
内容总结
以上是互联网集市为您收集整理的浅析vue component 组件使用全部内容,希望文章能够帮你解决浅析vue component 组件使用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。