Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript VueJS:无法读取属性';名称';“未定义”的定义;_Javascript_Vue.js - Fatal编程技术网

Javascript VueJS:无法读取属性';名称';“未定义”的定义;

Javascript VueJS:无法读取属性';名称';“未定义”的定义;,javascript,vue.js,Javascript,Vue.js,我无法理解并找到解决这个问题的办法。我正在尝试使用编辑表单编辑酒吧时间表: pubs/UpdateProfile.vue 在我的控制器中: PubsController.php 酒吧 schedulesDisplayed来自发布和计划模型之间的关系(pubSchedules:1pub x N schedules): 编辑后单击“保存”按钮时,我可以显示控制器中的消息“Hola”,但我有以下错误,无法继续开发表单: app.js:56802 [Vue warn]: Error in render:

我无法理解并找到解决这个问题的办法。我正在尝试使用编辑表单编辑酒吧时间表:

pubs/UpdateProfile.vue 在我的控制器中:

PubsController.php 酒吧 schedulesDisplayed来自发布和计划模型之间的关系(pubSchedules:1pub x N schedules):

编辑后单击“保存”按钮时,我可以显示控制器中的消息“Hola”,但我有以下错误,无法继续开发表单:

app.js:56802 [Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"

found in

---> <UpdateProfile> at 
resources/assets/js/components/pubs/UpdateProfile.vue
   <Pubs> at resources/assets/js/components/Pubs.vue
     <Root>
app.js:56802[Vue warn]:呈现时出错:“TypeError:无法读取未定义的属性“name”
发现于
--->在
resources/assets/js/components/pubs/UpdateProfile.vue
位于resources/assets/js/components/Pubs.vue

我在函数和.vue视图中找不到名为“name”的内容。我做错了什么?

您的UpdatePlengingTime函数应该是这样的:

updateOpeningTime(schedule) {
    var instance = this;

    this.api.put('/pubschedules/' + this.data.id, schedule).then(response => {
        instance.data = response.data;
    });
}

否则,在API调用的“then”中,单词
this
没有引用组件的实例。

问题应该是,在UpdatePeningTime函数中,您正在分配
this.data=response.data
,但
this
不是您的组件实例。在api调用之前,将其分配给局部变量,并在承诺响应中引用该变量。编辑:你能发布更多Vue组件的代码吗?非常感谢tanathos的回答,但是你能用一个例子(使用我的代码)向我解释一下吗?ThanksI使用my hole vue代码@tanathos编辑
updateOpeningTime(schedule){
            this.api.put('/pubschedules/' + this.data.id + '/' + schedule).then(response => {
                this.data = response.data;
            });
        }, 
public function updateOpeningTime(Pub $pub)
{
    json_die("Hola");

    json_die($pub->id);

    Schedule::where(['pub_id', $pub->id])->update(['opening_time' => request()->all()]);
}
export default class Pub {

constructor() {
    this.id = null;
    this.name = null;
    this.schedulesDisplayed = null;
  }
};
/**
 * @return \Illuminate\Database\Eloquent\Collection
 */
public function getSchedulesDisplayedAttribute()
{
    return $this->pubSchedules()->get();
}
app.js:56802 [Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"

found in

---> <UpdateProfile> at 
resources/assets/js/components/pubs/UpdateProfile.vue
   <Pubs> at resources/assets/js/components/Pubs.vue
     <Root>
updateOpeningTime(schedule) {
    var instance = this;

    this.api.put('/pubschedules/' + this.data.id, schedule).then(response => {
        instance.data = response.data;
    });
}