【问题标题】:Vue.js slider with local image doesn't work带有本地图像的 Vue.js 滑块不起作用
【发布时间】:2022-01-25 20:31:00
【问题描述】:

您好,我在“digitalocean.com”上找到了适用于 Vue.js 的此图像滑块,但仅适用于(imgbb、pixabay 等)上传的图像。我尝试设置本地图像(在资产上)但不起作用,有人可以帮助我吗? 我已经尝试过 ../assets/castelgandolfo.jpg 或 ./assets/castelgandolfo.jpg 对不起我的英语!

这是代码:

export default {
  name: "Slider",
  data() {
    return {
      images: [
        "https://i.ibb.co/6NJ7p6w/Castelgandolfo.jpg",
        "https://i.ibb.co/QJN06cG/Grottaferrata.jpg",
        "https://i.ibb.co/R3pHtGx/Ariccia.jpg",
      ],
      timer: null,
      currentIndex: 0
    };
  },

  mounted: function() {
    this.startSlide();
  },

  methods: {
    startSlide: function() {
      this.timer = setInterval(this.next, 10000);
    },

    next: function() {
      this.currentIndex += 1;
    },
    prev: function() {
      this.currentIndex -= 1;
    }
  },

  computed: {
    currentImg: function() {
      return this.images[Math.abs(this.currentIndex) % this.images.length];
    }
  }
};

【问题讨论】:

    标签: javascript html css vue.js


    【解决方案1】:

    您可以使用“@”直接引用图片

    例子:

    <img src="@/assets/images/home.png"/>
    

    【讨论】:

    • 我可以在数组中使用这个“@/assets/images/home.png”吗?
    • 是的,或者只是在&lt;img&gt;标签中添加@,就像&lt;imc :src="'@'+img.src"&gt;一样
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-11
    • 2018-08-02
    • 1970-01-01
    相关资源
    最近更新 更多