mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 06:59:15 +08:00
docs(Circle): use composition api
This commit is contained in:
parent
e4eb2d07d7
commit
42916dd50f
@ -24,17 +24,18 @@ app.use(Circle);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref, computed } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
|
const currentRate = ref(0);
|
||||||
|
const text = computed(() => currentRate.value.toFixed(0) + '%');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentRate: 0,
|
text,
|
||||||
|
currentRate,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
text() {
|
|
||||||
return this.currentRate.toFixed(0) + '%';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -72,14 +73,19 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
|
const currentRate = ref(0);
|
||||||
|
const gradientColor = {
|
||||||
|
'0%': '#3fecff',
|
||||||
|
'100%': '#6149f6',
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentRate: 0,
|
currentRate,
|
||||||
gradientColor: {
|
gradientColor,
|
||||||
'0%': '#3fecff',
|
|
||||||
'100%': '#6149f6',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -30,17 +30,18 @@ app.use(Circle);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref, computed } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
|
const currentRate = ref(0);
|
||||||
|
const text = computed(() => currentRate.value.toFixed(0) + '%');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentRate: 0,
|
text,
|
||||||
|
currentRate,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
text() {
|
|
||||||
return this.currentRate.toFixed(0) + '%';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -84,14 +85,19 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
|
const currentRate = ref(0);
|
||||||
|
const gradientColor = {
|
||||||
|
'0%': '#3fecff',
|
||||||
|
'100%': '#6149f6',
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentRate: 0,
|
currentRate,
|
||||||
gradientColor: {
|
gradientColor,
|
||||||
'0%': '#3fecff',
|
|
||||||
'100%': '#6149f6',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
:speed="100"
|
:speed="100"
|
||||||
:clockwise="false"
|
:clockwise="false"
|
||||||
:text="t('counterClockwise')"
|
:text="t('counterClockwise')"
|
||||||
style="margin-top: 15px;"
|
style="margin-top: 15px"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<van-circle
|
<van-circle
|
||||||
@ -52,11 +52,11 @@
|
|||||||
size="120px"
|
size="120px"
|
||||||
:clockwise="false"
|
:clockwise="false"
|
||||||
:text="t('customSize')"
|
:text="t('customSize')"
|
||||||
style="margin-top: 15px;"
|
style="margin-top: 15px"
|
||||||
/>
|
/>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<div style="margin-top: 15px;">
|
<div style="margin-top: 15px">
|
||||||
<van-button :text="t('add')" type="primary" size="small" @click="add" />
|
<van-button :text="t('add')" type="primary" size="small" @click="add" />
|
||||||
<van-button
|
<van-button
|
||||||
:text="t('decrease')"
|
:text="t('decrease')"
|
||||||
@ -67,51 +67,62 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
const format = (rate) => Math.min(Math.max(rate, 0), 100);
|
import { reactive, toRefs } from 'vue';
|
||||||
|
import { useTranslate } from '@demo/use-translate';
|
||||||
|
|
||||||
|
const format = (rate: number) => Math.min(Math.max(rate, 0), 100);
|
||||||
|
|
||||||
|
const i18n = {
|
||||||
|
'zh-CN': {
|
||||||
|
gradient: '渐变色',
|
||||||
|
customSize: '大小定制',
|
||||||
|
customStyle: '样式定制',
|
||||||
|
customColor: '颜色定制',
|
||||||
|
customWidth: '宽度定制',
|
||||||
|
counterClockwise: '逆时针',
|
||||||
|
},
|
||||||
|
'en-US': {
|
||||||
|
gradient: 'Gradient',
|
||||||
|
customSize: 'Custom Size',
|
||||||
|
customStyle: 'Custom Style',
|
||||||
|
customColor: 'Custom Color',
|
||||||
|
customWidth: 'Custom Width',
|
||||||
|
counterClockwise: 'Counter Clockwise',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
i18n: {
|
setup() {
|
||||||
'zh-CN': {
|
const t = useTranslate(i18n);
|
||||||
gradient: '渐变色',
|
const state = reactive({
|
||||||
customSize: '大小定制',
|
|
||||||
customStyle: '样式定制',
|
|
||||||
customColor: '颜色定制',
|
|
||||||
customWidth: '宽度定制',
|
|
||||||
counterClockwise: '逆时针',
|
|
||||||
},
|
|
||||||
'en-US': {
|
|
||||||
gradient: 'Gradient',
|
|
||||||
customSize: 'Custom Size',
|
|
||||||
customStyle: 'Custom Style',
|
|
||||||
customColor: 'Custom Color',
|
|
||||||
customWidth: 'Custom Width',
|
|
||||||
counterClockwise: 'Counter Clockwise',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
rate: 70,
|
rate: 70,
|
||||||
currentRate1: 70,
|
currentRate1: 70,
|
||||||
currentRate2: 70,
|
currentRate2: 70,
|
||||||
currentRate3: 70,
|
currentRate3: 70,
|
||||||
currentRate4: 70,
|
currentRate4: 70,
|
||||||
gradientColor: {
|
});
|
||||||
'0%': '#3fecff',
|
|
||||||
'100%': '#6149f6',
|
const gradientColor = {
|
||||||
},
|
'0%': '#3fecff',
|
||||||
|
'100%': '#6149f6',
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
const add = () => {
|
||||||
add() {
|
state.rate = format(state.rate + 20);
|
||||||
this.rate = format(this.rate + 20);
|
};
|
||||||
},
|
|
||||||
|
|
||||||
reduce() {
|
const reduce = () => {
|
||||||
this.rate = format(this.rate - 20);
|
state.rate = format(state.rate - 20);
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
t,
|
||||||
|
add,
|
||||||
|
reduce,
|
||||||
|
gradientColor,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user