mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-10 14:39:45 +08:00
docs(ImagePreview): use composition api
This commit is contained in:
parent
9fbda243cf
commit
3d05e56195
@ -88,22 +88,27 @@ setTimeout(() => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { reactive, toRefs } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const state = reactive({
|
||||||
show: false,
|
show: false,
|
||||||
index: 0,
|
index: 0,
|
||||||
|
});
|
||||||
|
const onChange = (index) => {
|
||||||
|
state.index = index;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
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',
|
||||||
],
|
],
|
||||||
|
onChange,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
|
||||||
onChange(index) {
|
|
||||||
this.index = index;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -123,22 +123,27 @@ setTimeout(() => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { reactive, toRefs } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const state = reactive({
|
||||||
show: false,
|
show: false,
|
||||||
index: 0,
|
index: 0,
|
||||||
|
});
|
||||||
|
const onChange = (index) => {
|
||||||
|
state.index = index;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
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',
|
||||||
],
|
],
|
||||||
|
onChange,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
|
||||||
onChange(index) {
|
|
||||||
this.index = index;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block card :title="t('componentCall')">
|
<demo-block card :title="t('componentCall')">
|
||||||
<van-cell is-link @click="componentCall">
|
<van-cell is-link @click="showComponentCall">
|
||||||
{{ t('componentCall') }}
|
{{ t('componentCall') }}
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<van-image-preview v-model:show="show" :images="images" @change="onChange">
|
<van-image-preview v-model:show="show" :images="images" @change="onChange">
|
||||||
@ -34,7 +34,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { reactive, toRefs } from 'vue';
|
||||||
|
import { useTranslate } from '../../composables/use-translate';
|
||||||
import ImagePreview from '..';
|
import ImagePreview from '..';
|
||||||
|
import Toast from '../../toast';
|
||||||
|
|
||||||
const images = [
|
const images = [
|
||||||
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
'https://img.yzcdn.cn/vant/apple-1.jpg',
|
||||||
@ -69,36 +72,33 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
setup() {
|
||||||
return {
|
const t = useTranslate();
|
||||||
|
const state = reactive({
|
||||||
show: false,
|
show: false,
|
||||||
images,
|
|
||||||
index: 0,
|
index: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const onClose = () => {
|
||||||
|
Toast(t('closed'));
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
const beforeClose = () =>
|
||||||
onClose() {
|
new Promise((resolve) => {
|
||||||
this.$toast(this.t('closed'));
|
|
||||||
},
|
|
||||||
|
|
||||||
beforeClose() {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
componentCall() {
|
const showComponentCall = () => {
|
||||||
this.show = true;
|
state.show = true;
|
||||||
},
|
};
|
||||||
|
|
||||||
onChange(index) {
|
const onChange = (index) => {
|
||||||
this.index = index;
|
state.index = index;
|
||||||
},
|
};
|
||||||
|
|
||||||
showImagePreview(options = {}) {
|
const showImagePreview = (options = {}) => {
|
||||||
const instance = ImagePreview({
|
const instance = ImagePreview({
|
||||||
images,
|
images,
|
||||||
...options,
|
...options,
|
||||||
@ -109,7 +109,17 @@ export default {
|
|||||||
instance.close();
|
instance.close();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
images,
|
||||||
|
onClose,
|
||||||
|
onChange,
|
||||||
|
beforeClose,
|
||||||
|
showImagePreview,
|
||||||
|
showComponentCall,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user