怎么定义一个自己的vue组件
2024-10-21 15:49:04
1.在src文件夹中创建一个hello文件夹,然后创建hello.js和hello.vue
2.hello.vue代码如下
<template>
<button>这是hello按钮</button>
</template> <script>
export default { }
</script> <style>
button {
width: 200px;
height: 50px;
background-color: pink;
border-radius: 20px;
}
</style>
3.hello.js代码如下
// 导入我们刚刚写的hello.vue文件
import HelloComponent from './hello.vue' const hello = {
// 将来这个 hello插件,被vue.use时,会自动调用内部的install方法,进行一些全局组件的注册
install: function (Vue) {
Vue.component('hello', HelloComponent)
}
}
// 导出
export default hello
4.在App.vue中直接使用
<template>
<div id="app">
//hello组件
<hello></hello>
</div>
</template> <style lang="less">
</style>
5.在main.js文件中引入,代码如下
import Vue from 'vue'
import App from './App.vue'
import store from './store'
// 引入
import hello from './hello/hello.js' Vue.config.productionTip = false // 进行一些全局组件的注册,以及一些其他的全局初始化
Vue.use(hello) new Vue({
render: h => h(App),
// 挂载vuex
store
}).$mount('#app')
5.一个简单的vue组件就写好了,看一下运行效果
最新文章
- Linux 查找进程运行位置
- Weblogic新增域(可以配置新端口)
- 【uTenux实验】集合点端口
- Kooboo中怎么写Page Plugin -摘自官方文档
- 1003: A Bug
- HttpClient---------demo
- 富文本NSAttributeString
- 数据库之redis篇(2)—— redis配置文件,常用命令,性能测试工具
- 微信小程序中的app.js-清除缓存
- PowerDesigner 12.5 汉化包-CSDN下载
- 小程序https请求,http网站升到https
- 什么是less?
- 截断文件函数truncate和ftruncate
- linux配置虚拟主机
- js jquery 取得周月年时间
- C# 利用反射将枚举绑定到下拉框
- C# winform开发嵌套Chrome内核浏览器(WebKit.net)开发(一)
- Shiro的使用
- [OI向?] ubuntu下一些常用的技巧
- TransactionScope 的基本原理简介
热门文章
- 总结一下 IEnumerable 的例子
- 我的第一个 60 k+ Star Java开源项目
- nyoj 36-最长公共子序列 (动态规划,DP, LCS)
- Bootstrap——面包屑导航(Breadcrumbs)
- 【SpringBoot | Redis】SpringBoot整合Redis
- 力扣(LeetCode)查找常用字符 个人题解
- tomcat-9.0.20缓存空间不足
- HTTP 协议漫谈
- Golang 入门系列(十六)锁的使用场景主要涉及到哪些?读写锁为什么会比普通锁快
- Spring Security框架下实现两周内自动登录";记住我";功能