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.

Vue.extend prototype

See original GitHub issue

Version

2.6.7

Reproduction link

https://repl.it/@Ti_webdev/Vue-extend

Steps to reproduce

const Vue2 = Vue.extend({})
Vue2.prototype.$foo = 'bar'

const Child = {
  render (h) {
    return h('h1', 'Hello Vue.extend! '   this.$foo)
  }
}

new Vue2({
  render (h) {
    return h(Child)
  },
  el: "#app"
}).$mount()

What is expected?

Hello Vue.extend! bar

What is actually happening?

Hello Vue.extend! undefined

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
posvacommented, Mar 1, 2019

that’s normal, Child is also extending Vue, you can make it extend Vue2 though:

const Child = Vue2.extend({
  render (h) {
    return h('h1', 'Hello Vue.extend! ' +  this.$foo)
  }
})
0reactions
Ti-webdevcommented, Mar 1, 2019

Unfortunately I have more complicated case where your way does not work 😦 I want to isolate third-party library with code like in the example http://jsfiddle.net/vg8y5n34/3/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending Vue - vue.js
prototype. The convention here is Vue instance methods should be prefixed with $ , so that they don't conflict with user data and...
Read more >
How to use the vue.extend function in vue - Snyk
To help you get started, we've selected a few vue.extend examples, based on popular ways it is used in public projects.
Read more >
Accessing properties globally in Vue.js with prototypes
Vue.js prototypes can vastly increase efficiency by letting you access properties globally instead of using multiple imports.
Read more >
Adding Instance Properties to a Vue App | by John Au-Yeung
We can extend Vue 's prototype to add global properties and methods that we can use throughout our app. We must reference them...
Read more >
How can create Vue.prototype from component?
AuthenDialog.install = (Vue, options) => { Object.defineProperty(Vue.prototype, '$authen', new Vue.extend(AuthenDialog)) }.
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