代码拉取完成,页面将自动刷新
在线文档 https://hsian.github.io/vc-dist/index.html#/component/button
# 克隆仓库
git clone https://github.com/hsian/vue-component.git
cd vue-component and npm install
yarn serve or npm run serve
组件开发准备工作
组件项目通常源于业务方的需求,大部分项目比如商城网站,后台管理系统,各类型站点都会有很多复用的地方,复用的地方抽离出来封装为一个组件,在需要的地方调用。
使用bootstrap
文档是团队在组件维护和使用中非常重要的一部分
目前技术人员常用的方式是采用markdown来编写文档,这里需要考虑几个问题:
初始化站点 vue ui
或 vue create [project]
项目目录文件夹
-assets
-css
-components
-docs
-pages
-template
-App.vue
-main.js
-nav.config.json
-router.config.js
vue-md-loader
加载markdown文档(参考example)nav.config.json代码片段
{
"component": {
"name": "组件",
"path": "/component",
"groups": [
{
"name": "基础组件",
"list": [
{
"path": "/button",
"title": "组件_button"
},
{
"path": "/modal",
"title": "组件_modal"
}
]
}
]
}
}
route.config.js代码片段
const load = function(path) {
return r => require.ensure([], () =>
r(require(`./pages${path}.vue`))
);
};
const loadDocs = function(path) {
return r => require.ensure([], () =>
r(require(`./components${path}.vue`))
);
};
const registerRoutes = function(){
const routes = Object.keys(navs).map(key => {
const nav = navs[key];
let route = {
path: nav.path,
component: load(nav.path),
children: []
}
if(nav.groups){
nav.groups.forEach(group => {
const list = group.list;
list.forEach(item => {
route.children.push({
path: item.path.slice(1),
component: loadDocs(item.path),
meta: item.title
})
})
})
}
return route;
})
return routes;
}
遇到的问题:
组件根目录index.js代码片段
// component/index.js
import Button from "./button";
const components = [
Button
]
const UI = {
install: function(Vue){
components.map(v => {
Vue.component(v.name, v)
})
}
};
export default UI
// mian.js
Vue.use(UI);
属性 props
type
使用bootstrap的样式, 默认值 primary
)事件
加载阿里图标库,
属性 props
type
加载对应的图标属性 props
事件
由于template模板无法解析函数, 所以表单的验证逻辑和表单赋值都在form-item中实现
属性 props
事件方法
data
注入多个依赖
解决方法
inject: {
form: {
default: ""
},
formItem: {
default: ""
}
},
表单重置时行为监听,如表单重置,由button开始触发,重置form - form-item - input
解决方法
//template引用
<div class="hm-input-wrap" :data-action="action">
// 子组件监听行为变化
watch: {
action: function(){
if(this.action === "reset"){
this.currentValue = "";
this.iconType = "";
this.iconClass = "";
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型