详解vue组件开发脚手架
作者:laozhang 时间:2024-05-09 15:15:34
generator-vue-component可以快速生成自己的组件开发的脚手架,类似于vue-cli生成vue项目,这脚手架是目录结构是方便组件开发和调试
由于脚手架是由yeoman搭建,所以必须全局安装yeoman
npm install yo
然后全局安装generator-vue-component
npm install generator-vue-component -g
到项目目录,获取对应的开发模板
yo vue-component-developer
运行上面命令会弹出下面,依次输入对应的信息,到Your component type这一步可以选择对应的组件类型,有组件和指令两种模板,选择完成后输入对应的组件名称或者指令名称即可,例如我们声明的组件名为vue-table
在vueTable目录下安装对应的模块,后运行下面命令即可
npm i && npm run dev
目录结构
index.js
此文件是vue组件声明并导出
import VueTable from './src/components/VueTable.vue';
VueTable.install = function (Vue) {
Vue.component(VueTable.name, VueTable)
};
export default VueTable;
components/VueTable.vue
开发的组件文件
<style lang="scss" scoped>
</style>
<template>
<div>
<h1>{{ title }}</h1>
<button @click="handleClick">click</button>
</div>
</template>
<script>
export default {
name: "vue-table",
data() {
return {
title: "vue-table"
};
},
methods: {
handleClick: function () {
alert("vue-table");
}
},
mounted() {
}
};
</script>
App.vue
App.vue是用来测试组件的使用
<template>
<div id="app">
<vue-table></vue-table>
</div>
</template>
<script>
export default {
name: 'app',
data() {
return {}
}
}
</script>
<style lang="scss">
</style>
主要用来编写代码的文件有components/VueTable.vue和demo/App.vue,一个用来开发,一个用来测试,其他不需要管
开发完怎么办?
开发完成可以有两个选择
本地安装 npm install 项目的本地路径
发布到npm,远程安装 npm install vue-table
如何使用?
import VueTable from 'vue-table'
Vue.use(VueTable);
github地址
最后附上github地址,给个star吧!https://github.com/KELEN/generator-vue-component-developer
来源:https://www.kelen.cc/posts/5b223a9aba8cc26a00423545
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
BootStrap 表单控件之单选按钮水平排列
![](https://img.aspxhome.com/file/2023/2/125942_0s.png)
安装配置Zabbix来监控MySQL的基本教程
![](https://img.aspxhome.com/file/2023/1/92261_0s.png)
Python常见数字运算操作实例小结
Django的分页器实例(paginator)
ASP也使用ORM,给ASP上所有的SQL注入画上句号
MySQL高级查询方法之记录查询
JavaScript 组件之旅(四):测试 JavaScript 组件
![](https://img.aspxhome.com/file/UploadPic/200910/13/smart-queue-test-41s.png)
ACCESS 2007出现“错误 '80040e14'“
python3设计模式之简单工厂模式
js循环改变div颜色具体方法
python生成验证码图片代码分享
![](https://img.aspxhome.com/file/2023/0/118090_0s.png)
设计从"心"开始
win10环境下使用Hyper-V进行虚拟机创建的教程(图解)
![](https://img.aspxhome.com/file/2023/5/131875_0s.jpg)
PHP如何利用P3P实现跨域
Eclipse+Java+Swing+Mysql实现电影购票系统(详细代码)
![](https://img.aspxhome.com/file/2023/5/94375_0s.png)
SQL语句学习
MySQL索引失效原理
![](https://img.aspxhome.com/file/2023/1/107421_0s.png)
Python里字典的基本用法(包括嵌套字典)
![](https://img.aspxhome.com/file/2023/7/95377_0s.png)
Python中endswith()函数的基本使用
python3+dlib实现人脸识别和情绪分析
![](https://img.aspxhome.com/file/2023/2/76032_0s.png)