js-IPFS / vue.js 上传错误 - 对象不可异步迭代

js-IPFS / vue.js upload error - Object is not async iterable

我一直在研究 js-ipfs (0.49.0),这工作正常,但我开始遇到一些问题,无论如何我终于回来再次查看代码并且连接工作正常但是当我尝试上传时出现新错误

对象不是异步可迭代的

我不确定这意味着什么或如何在我的代码中解决很多示例是针对 React 而不是 Vue

任何指针都非常适用。

methods: {
    async getIpfsNodeInfo() {
      try {
        // Await for ipfs node instance.
        node = await ipfs
        // console.log(node)
        // Call ipfs `id` method.
        // Returns the identity of the Peer.
        const { agentVersion, id } = await node.id()
        this.agentVersion = agentVersion
        this.id = id
        // Set successful status text.
        this.status = 'Connected to IPFS '
      } catch (err) {
        // Set error status text.
        this.status = `Error: ${err}`
      }
    },

    onFileSelected(event) {
      this.selectedFile = event.target.files[0]
      this.saveIPFS()
    },

    async saveIPFS() {
      try {
        for await (const result of node.add(this.selectedFile)) {
        
          this.fileContents = result
          this.getIPFS()
        }
      } catch (err) {
        // Set error status text.
        this.status = `Error: ${err}`
      }
    },

ipfs.add returns 自 ipfs@0.48.0 以来的单个对象 - 您需要更改:

   async saveIPFS() {
      try {
        for await (const result of node.add(this.selectedFile)) {
        
          this.fileContents = result
          this.getIPFS()
        }
      } catch (err) {
        // Set error status text.
        this.status = `Error: ${err}`
      }
    },

至:

   async saveIPFS() {
      try {
        this.fileContents = await node.add(this.selectedFile)
        this.getIPFS()
      } catch (err) {
        // Set error status text.
        this.status = `Error: ${err}`
      }
    },

有关更多信息,请参阅博客 post:https://blog.ipfs.io/2020-07-20-js-ipfs-0-48/#ipfs-add