开发Vue组件库

使用脚手架新建vue项目(以button 组件为例)
1.新建package 文件夹,添加index.js 、custombutton 文件夹,custombutton 中 添加
custombutton .vue
index.js

<template>
  <div>
    button
  </div>
</template>

<script>
export default {
  name: 'custombutton '
}
</script>

<style>
</style>
import custombutton from './custombutton .vue';
// 此处为按需加载使用
canvasBroad.install = Vue => Vue.component(canvasBroad.name, canvasBroad);//注册组件

export default custombutton 

packages/index.js

import custombutton from './custombutton/index ' 

// 存储组件列表
const components = [
    custombutton
]

// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
const install = function (Vue) {
// 判断是否安装
if (install.installed) return
    // 遍历注册全局组件
    components.map(component => Vue.component(component.name, component))
}

// 判断是否是直接引入文件
if (typeof window !== 'undefined' && window.Vue) {
    install(window.Vue)
}

export default {
    // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
    install,
    // 以下是具体的组件列表
    ...components
}

在package.json 添加

"lib": "vue-cli-service build --target lib --name custom --dest lib packages/index.js"

相关推荐

  1. 开发Vue

    2024-04-03 07:34:04       16 阅读
  2. Vue UI

    2024-04-03 07:34:04       12 阅读
  3. 学习搭建Vue

    2024-04-03 07:34:04       34 阅读
  4. Vue学习:22.Vue-Vant

    2024-04-03 07:34:04       15 阅读
  5. Vue.js - 界面设计工具和UI

    2024-04-03 07:34:04       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-03 07:34:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-03 07:34:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-03 07:34:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-03 07:34:04       20 阅读

热门阅读

  1. css预编译sass,css也可以变得优雅

    2024-04-03 07:34:04       16 阅读
  2. head和body引入js的问题

    2024-04-03 07:34:04       16 阅读
  3. Vue2 和 Vue3 中的 v-model 的区别#记录

    2024-04-03 07:34:04       14 阅读
  4. php使用swoole实现TCP服务

    2024-04-03 07:34:04       15 阅读
  5. XML的基础知识及XMl文件的创建/读取/更新demo详解

    2024-04-03 07:34:04       16 阅读
  6. XML与Xpath

    2024-04-03 07:34:04       13 阅读