【问题标题】:Data is displayed in the vue console but not returned to the web page数据在vue控制台显示但不返回网页
【发布时间】:2020-03-11 03:43:05
【问题描述】:

文件上传.vue

<template>
<div>
   <vue-dropzone
           :options="dropzoneOptions">      
      <div class="dropzone-custom-content" id="custom">
        <h3 class="dropzone-custom-title">Drag & Drop</h3>       
      </div>
   </vue-dropzone>
    <div>
        Content: {{testmsg}}
    </div>
</div>
</template>

<script>
import vue2Dropzone from "vue2-dropzone";
import 'vue2-dropzone/dist/vue2Dropzone.min.css'
export default {
    components: {
        vueDropzone: vue2Dropzone,
    },
    data() {
        return {
            dropzoneOptions: {
                url: 'http://localhost:5000/',
                method: "post",
                maxFiles: 1,
                thumbnailWidth: 300,
                maxFilesize: 500,
                success: function (file, responejson) {
                    this.msg = responejson
                    console.log(this.msg)
                    this.testmsg='Hi'
                    console.log(this.testmsg)
                },

console.log(this.testmsg)=>嗨

上传图片后,网络上不会出现值Hi。

附上图片。 控制台窗口结果和场景不会出现在网络上。

这是控制台窗口结果。

内容:没有值出现。

【问题讨论】:

  • 你能声明 let $this = this.然后将 this.testmsg 更改为 $this.testmsg
  • 让$这个=这个?我应该在哪里申报?
  • 让 $this= this 把它放在你的成功函数中,然后在成功函数中把它全部改成 $this,而不是使用这个。顺便说一句,您也可以更改它,它不一定是 $this,您可以随心所欲地更改它。
  • @Renato Manalili 仍然没有回应
  • 你是如何渲染 testmsg 的?你有 vue 开发工具吗?它还可以帮助您查看 testmsg 是否收到了数据。

标签: vue.js


【解决方案1】:

data 中没有 testmsg 属性。应该是:

data: () => ({
    testmsg: '',
    dropzoneOptions: {
          // rest of your code
     }
})

【讨论】:

  • success(file, responejson) { this.msg = responejson console.log(this.msg) }
  • 如何从放置区返回味精数据?
  • 看起来你想要做的是将dropzone的东西移动到一个方法中,而不是在数据中。
  • 这可能吗?
  • 可以说明吗?成功
猜你喜欢
  • 2021-10-23
  • 2019-08-15
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多