How to gracefully obtain the this instance of vue in an ordinary js file?

have you tried it yourself? There is no $createElement in import Vue from "vue"

.
import Vue from "vue"

console.log(Vue.$createElement)
undefined

console.log(Vue.prototype.$createElement)
undefined

for example, I want to use the this.$createdElement method, but I only introduce vue. There is no attribute of $createdElement on the prototype of vue, but only the vue instance. What should I do?

and elegant, officially recommended

my solution now is to add this attribute to the vue object when vue created in main.js

Mar.25,2022

clipboard.png

https://codeshelper.com/q/10.


import Vue from 'vue'
let v = new Vue ();


the solution is to assign a value to the prototype chain in the create function in main.js


ide/render-function.html-sharpcreateElement-%E5%8F%82%E6%95%B0" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.
you have to use the rendering function to access


Vue.prototype.$createElement

does the subject know the prototype chain?

< hr >

update it.

I apologize for the wrong answer above. It was wrong of me to answer without proper verification.

however, the questioner's attitude was so bad that I didn't bother to correct the answer.

Menu