这次给大家带来有哪些vue组件的书写方法,使用vue组件的注意事项有哪些,下面就是实战案例,一起来看一下。
第一种使用script标签
<-- 注意:使用标签时,type指定为text/x-template,意在告诉浏览器这不是一段js脚本,浏览器在解析HTML文档时会忽略标签内定义的内容。--> //注意 type 和id。
This is a component!
//全局注册组件 Vue.component('my-component',{ template: '#myComponent' }) new Vue({ el: '#app' })
登录后复制
第二种使用template标签
This is a component!
Vue.component('my-component',{ template: '#myComponent' }) new Vue({ el: '#app' })
登录后复制
第三种 单文件组件
这种方法常用在vue单页应用中。详情看官网:https://cn.vuejs.org/v2/guide/single-file-components.html
创建.vue后缀的文件,组件Hello.vue,放到components文件夹中
{{ msg }}
export default { name: 'hello', data () { return { msg: '欢迎!' } }}
登录后复制
app.vue
// 导入组件import Hello from './components/Hello'export default { name: 'app', components: { Hello }}#app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px;}
登录后复制
相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!
推荐阅读:
立即学习“前端免费学习笔记(深入)”;
新手必看的js实现异步方法
通过JS获取JSON数据并加载的步骤详解
以上就是有哪些vue组件的书写方法的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2772385.html