【发布时间】:2019-12-06 15:19:39
【问题描述】:
我为我的应用创建了一个自定义组件,用于为产品选择多个图像:
<template>
<!-- Image modal -->
<div
class="modal fade"
id="gallery-multi"
tabindex="-1"
role="dialog"
aria-labelledby="galleryLabel"
aria-hidden="true"
>
<div class="modal-dialog modal-dialog-centered modal-lg " role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="gallery">Gallery</h5>
<button type="button" class="close" @click="closeModal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<vue-select-image
:dataImages="dataImages"
:is-multiple="true"
@onselectmultipleimage="onSelectMultipleImage"
:h="'90'"
:w="'140'"
></vue-select-image>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" @click="closeModal()">Close</button>
</div>
</div>
</div>
</div>
</template>
<script>
import VueSelectImage from "vue-select-image";
import "vue-select-image/dist/vue-select-image.css";
export default {
name: "selectMultiImg",
data() {
return {
multiID:[],
dataImages: [
{
id: "",
src: "",
alt: ""
}
]
};
},
methods: {
closeModal() {
$("#gallery-multi").modal("hide");
},
onSelectMultipleImage: function(data) {
this.multiID = data.id;
this.$emit('multiImg', this.multiID);
}
},
components: { VueSelectImage },
mounted() {
axios.get("/api/gallery").then(response => {
this.dataImages = response.data.map((obj, index) => {
return {
id: obj.id,
src: obj.thumb,
alt: obj.name
};
});
});
}
};
</script>
我也在其他路线(主要路线)中使用此组件,例如:
{
path: "/product-category",
component: require("./components/product/Category.vue")
},
它在主要路线上运行平稳。但是我在嵌套路由中遇到了麻烦:
{
path: "/product/create",
component: require("./components/product/Create.vue"),
},
在上图中,图片的原始路径是src="img/thumb_dcb7d855594bb92d2fd83108e8a2620e.jpg",但路径的高亮部分是http://localhost:3000/product/img/thumb_dcb7d855594bb92d2fd83108e8a2620e.jpg p>
这是由 vue 本身添加的(我想)。此外,控制台也没有错误。
谁能帮我找出造成这种情况的原因及其可能的解决方案?
【问题讨论】:
-
图片的确切位置是什么?
标签: javascript vue.js vuejs2 vue-component vue-router