mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs(Swipe): use composition api
This commit is contained in:
parent
6150e21f4a
commit
d297807f55
@ -50,13 +50,12 @@ Use `lazy-render` prop to enable lazy rendering.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const images = [
|
||||||
images: [
|
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
||||||
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
'https://img.yzcdn.cn/vant/apple-2.jpg',
|
||||||
'https://img.yzcdn.cn/vant/apple-2.jpg',
|
];
|
||||||
],
|
return { images };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -76,10 +75,11 @@ export default {
|
|||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
setup() {
|
||||||
onChange(index) {
|
const onChange = (index) => {
|
||||||
Toast('Current Swipe index:' + index);
|
Toast('Current Swipe index:' + index);
|
||||||
},
|
};
|
||||||
|
return { onChange };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -134,16 +134,18 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const current = ref(0);
|
||||||
current: 0,
|
const onChange = (index) => {
|
||||||
|
current.value = index;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
current,
|
||||||
|
onChange,
|
||||||
};
|
};
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
onChange(index) {
|
|
||||||
this.current = index;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -54,13 +54,12 @@ app.use(SwipeItem);
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const images = [
|
||||||
images: [
|
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
||||||
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
'https://img.yzcdn.cn/vant/apple-2.jpg',
|
||||||
'https://img.yzcdn.cn/vant/apple-2.jpg',
|
];
|
||||||
],
|
return { images };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -80,10 +79,11 @@ export default {
|
|||||||
import { Toast } from 'vant';
|
import { Toast } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
setup() {
|
||||||
onChange(index) {
|
const onChange = (index) => {
|
||||||
Toast('当前 Swipe 索引:' + index);
|
Toast('当前 Swipe 索引:' + index);
|
||||||
},
|
};
|
||||||
|
return { onChange };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -144,16 +144,18 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const current = ref(0);
|
||||||
current: 0,
|
const onChange = (index) => {
|
||||||
|
current.value = index;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
current,
|
||||||
|
onChange,
|
||||||
};
|
};
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
onChange(index) {
|
|
||||||
this.current = index;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -64,6 +64,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useTranslate } from '../../composables/use-translate';
|
||||||
|
import Toast from '../../toast';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
i18n: {
|
i18n: {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
@ -84,26 +88,30 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const t = useTranslate();
|
||||||
current: 0,
|
const current = ref(0);
|
||||||
images: [
|
const images = [
|
||||||
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
||||||
'https://img.yzcdn.cn/vant/apple-2.jpg',
|
'https://img.yzcdn.cn/vant/apple-2.jpg',
|
||||||
'https://img.yzcdn.cn/vant/apple-3.jpg',
|
'https://img.yzcdn.cn/vant/apple-3.jpg',
|
||||||
'https://img.yzcdn.cn/vant/apple-4.jpg',
|
'https://img.yzcdn.cn/vant/apple-4.jpg',
|
||||||
],
|
];
|
||||||
|
|
||||||
|
const onChange1 = (index) => {
|
||||||
|
Toast(t('message') + index);
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
const onChange2 = (index) => {
|
||||||
onChange1(index) {
|
current.value = index;
|
||||||
this.$toast(this.t('message') + index);
|
};
|
||||||
},
|
|
||||||
|
|
||||||
onChange2(index) {
|
return {
|
||||||
this.current = index;
|
images,
|
||||||
},
|
current,
|
||||||
|
onChange1,
|
||||||
|
onChange2,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user