簡體   English   中英

顯示JSON屬性

[英]Display JSON property

因此,我在Vue.js中創建了一個下拉組件,該組件使用戶能夠拖放文件,在他刪除文件后,他將被重定向到該文件顯示為JSON的另一個頁面。 目前,我的JSON如下所示:

{"upload":{"uuid":"fa90093a-534e-40fb-ab53-20edd78fad08","progress":0,"total":5197,"bytesSent":0,"filename":"svg-test.svg","chunked":false,"totalChunkCount":1},"status":"added","previewElement":{},"previewTemplate":{}}

我只想顯示文件名“:” svg-test.svg屬性,如何實現? 這是我的組件:

 mounted() {
   var dropzoneComponent = new Dropzone (
     '#dropzone',
     {
       url: 'file/upload',
       createImageThumbnails: false,
       previewsContainer: '#template-preview',
       acceptedFiles: '.svg',
       init: function() {
       this.on ('complete', function() {
          window.location.href='http://localhost:8080/edit-draft'
          })
      this.on('addedfile', function(file) {
            localStorage.setItem('file', JSON.stringify(file))
          })
       },
     }
   )
  },




Here it gets called from the LocalStorage
    data: () => ({
        mode: "edit",
        svgFile: localStorage.getItem('file'),
        floorStore: store.floor
      }),

您可以按以下方式訪問它:

JSON.parse(localStorage.getItem('file')).upload.filename

這里的關鍵點是您首先需要對其進行解析,因為將其保存到localStorage時已對其進行了字符串化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM