【问题标题】:[Vue warn]: Property or method "msg" is not defined on the instance but referenced during render. ("content")...etc[Vue 警告]:属性或方法“msg”未在实例上定义,但在渲染期间被引用。 (“内容”)...等
【发布时间】:2019-03-09 18:02:56
【问题描述】:

我的查看页面代码

<div id="app">
@{{ msg }}
@{{ content }}

在此处使用表单

<form method="post" enctype="multipart/form-data" v-on:submit.prevent="addPost">
                      <textarea v-model="content" id="postText" class="form-control"></textarea>
                <button type="submit" id="postBtn">Post</button>
            </form></div>

这是我的 app.js 代码

const app = new Vue({
    el: '#app',

在此处返回数据 数据: { 返回:{ msg: '发帖:', 内容: '', bUrl: 'http://localhost:8888/pathikhome', } }, 方法: { 获取 addpost 数据

        addPost(){
            axios.post(this.bUrl +'/addPost', {
                content: this.content
            })
                .then( (response) =>{
                    this.content="";
                    console.log('saved successfully'); // show if success
                    if(response.status===200){
                        app.posts = response.data;
                    }
                })
                .catch(function (error) {
                    console.log(error); // run if we have error
                });
        }
    }
});

【问题讨论】:

  • 加载数据后你正在做app.posts = response.data。什么是app?!

标签: php laravel vue.js


【解决方案1】:

试试这个代码:

    data: {
        msg: 'Make Post:',
       content: '',
       bUrl: 'http://localhost:8888/pathikhome',
     },

而不是你的代码:

  data: {
     return:{
        msg: 'Make Post:',
      content: '',
      bUrl: 'http://localhost:8888/pathikhome',
     }
   },

因为在您的代码中,您试图从一个对象返回一个对象。

【讨论】:

  • 为什么不把你的视图页面和你的app.js文件更清楚地展示给我们,你只展示了它们的一部分,我们很难调试
  • 当我试图在这里修改代码然后看到一些错误..添加一些类似这样的上下文..我希望现在更清楚
  • 我在您的代码中仍然看到相同的数据返回内容
猜你喜欢
  • 2017-11-14
  • 2021-08-13
  • 2021-02-10
  • 2020-07-25
  • 2017-04-08
  • 2019-02-20
  • 2021-11-27
相关资源
最近更新 更多