2

我在后端有两个图像,当我在网站(前端)上单击图像 1 时,我看到图像 1 的结果,因为它是硬编码的,当我单击图像 2 时,我也看到图像 1 的结果。如何制作我的代码,以便在单击单个图像时可以看到两个图像。任何人都可以给我一个提示吗?

我的代码:listImage.vue

    <template>
    <div class="fileUpload">
        <b-container fluid>
            <h4>Image Overview</h4>
            <b-button variant="success" class="btn-right" @click="uploadImage" method="post">Upload image</b-button>
            <div class="file">Selected file: {{selectedFile && selectedFile.name}}</div>
            <b-button v-model="selectedFile" variant="success" @click="$refs.fileInput.click()" class="btn-right">Select an image</b-button>
            <input style="display: none" ref="fileInput" type="file" @change="fileSelected" enctype="multipart/form-data">
            <b-table @row-clicked="viewImage" striped hover :items="images" :fields="image_fields"></b-table>
</b-container>
    </div>
</template>

<script>
    // eslint-disable-next-line
    /* eslint-disable */
    import axios from 'axios'
    export default {
        name: 'listImage',
        data() {
            return {
                selectedFile: null,
                images: [],
                image_fields: ['id', 'name'],
                total_images: 1,
               }
        },
        created() {
            this.loadImages(0, 10)
        },
        watch: {
            currentPage: function (newPage) {
                this.loadImages(newPage, 10)
            }
        },
        methods: {
            fileSelected(evt, e) {
                evt.preventDefault()
                console.log(evt);
                this.selectedFile = evt.target.files[0]
            },
            uploadImage() {
                var data = new FormData();
                data.append('image', this.selectedFile, this.selectedFile.data)
                var token = sessionStorage.getItem('token')
                const config = {
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    }
                }
                window.API.post('https://111.11.111.111:8080/images/?token=' + token, data, config)
                    .then(response => this.$router.push('/template')) //how to refresh the upload page
                    .catch((error) => {
                        console.log(JSON.stringify(error))
                    })
            },
            viewImage(record, index) {
                var id = record.id
                this.$router.push({ name: 'viewImage', params: { id } })//check the router in index.js
            },
            loadImage(e) {
            }
        }
    }
</script>

我的视图图像代码:

    <template>
  <b-container fluid>
    <h4>Images</h4>
    <div>
      <img v-bind:src="image" />
       </div>
  </b-container>
</template>
<script>
  // eslint-disable-next-line
  /* eslint-disable */
  export default {
    data() {
      return {
        image: ''
      }
    },
    created() {

      this.image = 'https:111.111.111.111/images/rearview.jpg?token=TX7PS-tCyTS1p72kHxo4594jjwf74'

    },
    methods: {
    }
  }
</script>
4

1 回答 1

1

解决了。

created() {
  var token = sessionStorage.getItem('token')
  window.API.get(`images/` + this.$route.params.id + '?token=' + token)
    .then(response => {
      this.fileName = response.data.name;
      this.image = 'data:image/png; base64, ' + response.data.data;
    })
    .catch(e => {
      this.errors.push(e)
    })
},
于 2018-03-14T08:47:34.363 回答