question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using @vue/compat, the beforeCreate hook in proxy.ts throws an exception:

this.$refs = new Proxy(...)
TypeError: 'set' on proxy: trap returned falsish for property

My Vue 3 fix is to change the hook to this:

beforeCreate() {
    this.$.refs = reactive({});
}

Note the period between the ‘$’ and the ‘refs’.

I swore I read somewhere that $refs was going to be reactive in Vue 3, but it seems not to be. Maybe I just imagined it…

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
diachedeliccommented, Mar 13, 2022

It is so easy to get reactive refs in Vue 3 that a plugin isn’t really justified. I recommend that you simply include the following beforeCreate hook in any component which depends on reactive refs:

import {reactive} from "vue";
export default {
    beforeCreate() {
        this.$.refs = reactive({});
    }
};

If you want reactive refs in every component automatically, add the hook globally:

import {createApp, reactive} from "vue";
const app = createApp(...);
app.mixin({
    beforeCreate() {
        this.$.refs = reactive({});
    }
});
0reactions
diachedeliccommented, Jul 20, 2022

Can it be fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue.js - The Progressive JavaScript Framework | Vue.js
Approachable. Builds on top of standard HTML, CSS and JavaScript with intuitive API and world-class documentation. · Performant. Truly reactive, compiler- ...
Read more >
Vue 3 – A roundup of infos about the new version of Vue.js
Vue 3 features & changes. As Evan You summarized it, Vue 3 is faster, smaller, more maintainable and it's easier to target native....
Read more >
vuejs/core: Vue.js is a progressive, incrementally ... - GitHub
Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web. - GitHub - vuejs/core: Vue.js is a progressive, ...
Read more >
What's new in Vue 3 — a roundup. Vue 3 - Medium
Vue 3 introduced the Composition API as an alternative method to the Options API for writing component states and logic. It's simply a...
Read more >
A definitive guide to Vue 3 components - LogRocket Blog
Vue apps consist of components, which are reusable pieces of UI code that build functional and complex web applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found