浏览 242
分享
Install 安装
npm install zarm-vue --save
还在使用1.0.x版本的,请使用如下安装指令
npm install zarm-vue@1.0 --save
使用Starter Kit
我们提供了通用的项目模板,你可以直接使用。如果不希望使用我们提供的模板,请继续阅读。
Import 引入
- 全组件引入
import Vue from 'vue';
import zarmVue from 'zarm-vue';
// 引入全局样式
import 'zarm-vue/zarm-vue.default.css';
Vue.use(zarmVue);
- 按需引入
借助ElementUI
提供的babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。
首先,安装 babel-plugin-component:
npm install babel-plugin-component -D
然后,将 .babelrc 添加:
{
// ...
"plugins": [["component", {
"libraryName": "zarm-vue",
"styleLibraryName": "theme"
}
]]
}
接下来,如果你只希望引入部分组件,比如 Button 和 Alert,那么需要在 main.js 中写入以下内容:
import { Button, Alert } from 'zarm-vue'
Vue.use(Button)
Vue.use(Alert)
全组件按需引入示例:
import {
Accordion,
AccordionItem,
Actionsheet,
Alert,
Badge,
Button,
Calendar,
Cell,
Checkbox,
CheckboxGroup,
Confirm,
DatePicker,
DatePickerView,
DateSelect,
Drag,
Icon,
Input,
InputNumber,
Keyboard,
KeyboardPicker,
Loading,
Mask,
Message,
Modal,
NoticeBar,
Panel,
PanelHeader,
PanelBody,
PanelFooter,
Picker,
PickerView,
Popup,
Progress,
Pull,
Radio,
RadioGroup,
SearchBar,
Select,
Slider,
Spinner,
StackPicker,
Stepper,
Swipe,
SwipeAction,
SwipeItem,
Switch,
Tabs,
TabPane,
Toast,
Tooltip,
Uploader,
} from 'zarm-vue'
const components = [
Accordion,
AccordionItem,
Actionsheet,
Alert,
Badge,
Button,
Calendar,
Cell,
Checkbox,
CheckboxGroup,
Confirm,
DatePicker,
DatePickerView,
DateSelect,
Drag,
Icon,
Input,
InputNumber,
Keyboard,
KeyboardPicker,
Loading,
Mask,
Message,
Modal,
NoticeBar,
Panel,
PanelHeader,
PanelBody,
PanelFooter,
Picker,
PickerView,
Popup,
Progress,
Pull,
Radio,
RadioGroup,
SearchBar,
Select,
Slider,
Spinner,
StackPicker,
Stepper,
Swipe,
SwipeAction,
SwipeItem,
Switch,
Tabs,
TabPane,
Toast,
Tooltip,
Uploader,
];
const install = function (Vue, opts = {}) {
/* istanbul ignore if */
if (install.installed) return;
components.map(component => Vue.component(component.name, component));
Vue.use(Loading.directive);
Vue.prototype.$zaToast = Toast.root;
Vue.prototype.$zaLoading = Loading.root;
Vue.prototype.$zaAlert = Alert.root;
Vue.prototype.$zaConfirm = Confirm.root;
};
install(Vue);
- 也可以通过cdn引入umd模块
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/zarm-vue@1.1.2/zarm-vue.default.css">
<script src="https://unpkg.com/vue@2.5.11/dist/vue.min.js"></script>
<script src="https://unpkg.com/zarm-vue@1.1.2/zarm-vue.umd.js"></script>
</head>
<body>
<div id="app">
<za-button theme="primary">普通按钮</za-button>
</div>
</body>
<script>
new Vue({
el: '#app'
})
</script>
</html>
集成Typescript开发
- 安装typescript相关依赖
npm install typescript ts-loader --save-dev
- webpack配置增加ts-loader支持示例
module.exports = {
// ...
resolve: {
extensions: ['.ts','.js', '.vue', '.json'],
},
module: {
rules: [
// ...
{
test: /\.ts$/,
loader: 'ts-loader',
include: [resolve('src'), resolve('test')],
options: {
appendTsSuffixTo: [/\.vue$/],
}
}
]
},
}
- 配置tsconfig.json
{
"compilerOptions": {
// 与 Vue 的浏览器支持保持一致
"target": "es5",
// 这可以对 `this` 上的数据属性进行更严格的推断
"strict": true,
// 如果使用 webpack 2+ 或 rollup,可以利用 tree-shake:
"module": "es2015",
"moduleResolution": "node"
},
"include": ["./src/**/*"]
}
- 添加vue-shims.d.ts文件
declare module "*.vue" {
import Vue from "vue";
export default Vue;
}
declare module 'zarm-vue' {
const ZarmVue: any;
export default ZarmVue;
}
评论列表