1. 1.vant-swiper-previewImage
  2. 2.单向数据流
  3. 3.双向数据绑定
  4. 4.实现类似于vant-ui的模态框
  5. 5.动态路由 router-link跳转
  6. 6.动态组件和 keep-alive

一、vant-swiper-previewImage

  1. <van-swipe :autoplay="false">
  2. <van-swipe-item v-for="(item, index) in images" @click="onChange(index)" :key="index">
  3. <img :src="item.imgUrl" />
  4. </van-swipe-item>
  5. </van-swipe>
  1. <script>
  2. import { ImagePreview } from "vant";
  3. import localData from "@/data/data.js";
  4. export default {
  5. data() {
  6. return {
  7. images: localData
  8. };
  9. },
  10. methods: {
  11. onChange(index) {
  12. const instance = ImagePreview({
  13. images: this.urls,
  14. asyncClose: true,
  15. startPosition: index
  16. });
  17. setTimeout(() => {
  18. instance.close();
  19. }, 1000);
  20. }
  21. },
  22. computed: {
  23. urls() {
  24. return this.images.map(item => item.imgUrl);
  25. }
  26. }
  27. };
  28. </script>
//data.js
var localData = [
    { imgUrl: "http://img1.qunarzz.com/sight/p0/1501/10/1012e4a2c398409c.water.jpg_350x240_56977146.jpg", id: 1000 },
    { imgUrl: "http://img1.qunarzz.com/sight/p0/201405/27/94685f45252d4f782f6545a7586e9daa.jpg_350x240_bfb5f7e5.jpg", id: 1001 },
    { imgUrl: "http://img1.qunarzz.com/sight/p0/201405/27/94685f45252d4f782f6545a7586e9daa.jpg_350x240_bfb5f7e5.jpg", id: 1002 },
    { imgUrl: "http://img1.qunarzz.com/sight/p0/201301/14/c14bcd857b804ca393835fbb.jpg_350x240_d84595e3.jpg", id: 1234 },
    { imgUrl: "http://img1.qunarzz.com/sight/p0/1509/fb/4bd1b1c83f5bc033ff36093b91294021.water.jpg_350x240_feb831ff.jpg", id: 1115 },
    { imgUrl: "http://img1.qunarzz.com/sight/p0/1412/5c/b921bad6734a811e28c2c8f7a22f83ba.water.jpg_350x240_874af7bd.jpg", id: 1116 },
]
export default localData;