Skip to content

Document improvement to this inside ComponentOptions #1013

Open
@sprhawk

Description

@sprhawk

I'm using typescript + vue-class-component + vue-apollo.

And I have following code:

 18 import Vue from 'vue'
 19 import Component from 'vue-class-component'
 20
 21 import { UsbDisk, OnUsbdisksChanged } from "generated/graphql";
 22
 23 @Component({
 24   apollo: {
 25     $subscribe: {
 26       usbDisksChanged: {
 27         query: OnUsbdisksChanged,
 28         result({ data }: any) {
 29           let disks: UsbDisk[] = data.usbDisksChanged;
 33           Vue.set(this, 'usbdisks', disks); // <- this is VueComponent
 34         }
 36       },
 37     }
 38   }})
 39 export default class DisksPage extends Vue {
 55
 56   usbdisks: UsbDisk[] = [];
 57
 58   created() {
 59   }
 60 }

On line 33, the this is referenced to VueComponent, and when I want to change some value for my class component I cannot just use this to change data like normally inside a vue context, I need to use Vue.set to do that.

I guess this is a scope restriction of vue-class-component, but I think it would be better add some document on this to help developers

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions