vant components
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# @youzan/<%= name %>
|
||||
|
||||
!!! 请在此处填写你的文档最简单描述 !!!
|
||||
|
||||
[![version][version-image]][download-url]
|
||||
[![download][download-image]][download-url]
|
||||
|
||||
[version-image]: http://npm.qima-inc.com/badge/v/@youzan/<%= name %>.svg?style=flat-square
|
||||
[download-image]: http://npm.qima-inc.com/badge/d/@youzan/<%= name %>.svg?style=flat-square
|
||||
[download-url]: http://npm.qima-inc.com/package/@youzan/<%= name %>
|
||||
|
||||
## Demo
|
||||
|
||||
## Usage
|
||||
|
||||
## API
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
||||
|-----------|-----------|-----------|-------------|-------------|
|
||||
| className | 自定义额外类名 | string | '' | '' |
|
||||
|
||||
|
||||
|
||||
|
||||
## License
|
||||
[MIT](https://opensource.org/licenses/MIT)
|
||||
@@ -0,0 +1,3 @@
|
||||
import Switch from './src/switch';
|
||||
|
||||
export default Switch;
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@youzan/van-switch",
|
||||
"version": "0.0.1",
|
||||
"description": "switch component",
|
||||
"main": "./index.js",
|
||||
"author": "jiangruowei",
|
||||
"license": "MIT",
|
||||
"devDependencies": {},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<template>
|
||||
<div class="van-switch" :class="switchStates" @click="toggleState">
|
||||
<div class="van-switch__node">
|
||||
<van-loading v-if="loading" class="van-switch__loading"></van-loading>
|
||||
</div>
|
||||
<div class="van-switch__bg"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VanLoading from 'packages/loading';
|
||||
/**
|
||||
* van-switch
|
||||
* @module components/switch
|
||||
* @desc 开关
|
||||
* @param {boolean} [value=false] - 开关状态
|
||||
* @param {boolean} [disabled=false] - 禁用
|
||||
* @param {boolean} [loading=false] - loading状态
|
||||
*
|
||||
* @example
|
||||
* <van-switch :checked="true" :disabled="false"></van-switch>
|
||||
*/
|
||||
export default {
|
||||
name: 'van-switch',
|
||||
components: {
|
||||
'van-loading': VanLoading
|
||||
},
|
||||
props: {
|
||||
value: Boolean,
|
||||
disabled: Boolean,
|
||||
loading: Boolean,
|
||||
onChange: Function
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
checked: this.value
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
checked(val) {
|
||||
this.$emit('input', val);
|
||||
},
|
||||
|
||||
value(val) {
|
||||
this.checked = val;
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
switchStates: function() {
|
||||
const switchStates = ['van-switch--' + (this.checked ? 'on' : 'off')];
|
||||
|
||||
if (this.disabled) {
|
||||
switchStates.push('van-switch--disabled');
|
||||
}
|
||||
|
||||
return switchStates;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/*
|
||||
* 开关状态交互。
|
||||
*/
|
||||
toggleState: function() {
|
||||
if (this.disabled || this.loading) return;
|
||||
if (this.onChange) {
|
||||
this.onChange(!this.checked);
|
||||
} else {
|
||||
this.checked = !this.checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user