vue-render

2022-07-09  本文已影响0人  tutututudou

main.js

import Vue from 'vue'
import App from './App.vue'

new Vue({
    router,
    el:'#app',
    components:{App},
    template:`<App></App>`,
});

vue.runtime.esm.js?2b0e:619 [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

(found in <Root>)


完整版引入如下:import Vue from 'vue/dist/vue'

import Vue from 'vue/dist/vue'//这是完整引入
import App from './App.vue'

new Vue({
    // router,
    el:'#app',
    components:{App},
    template:`<App></App>`,
});

// import Vue from 'vue/dist/vue'
import Vue from 'vue'//引入残缺版

new Vue({
    el:'#app',
    render(createElement){
        console.log(typeof createElement)//打印出来是个函数,默认传入的
        return null//必须要有返回值
    }
});
// import Vue from 'vue/dist/vue'
import Vue from 'vue'

new Vue({
    el:'#app',
    // components:{App},
    // template:`<App></App>`,
    render(createElement){
        // console.log(typeof createElement)
        return createElement('h1','你好啊~')//要返回元素标签h1,这就会被渲染了
    }
});
h1被添加渲染.PNG
// import Vue from 'vue/dist/vue'
import Vue from 'vue'
import App from './App.vue'
// import router from './router'

new Vue({
    // router,
    el:'#app',
    // components:{App},
    // template:`<App></App>`,
    // render: h => h(App),
    render(createElement){
        // console.log(typeof createElement)
        // return createElement('h1','你好啊~')
        return createElement(App)
    }
});
// import Vue from 'vue/dist/vue'
import Vue from 'vue'
import App from './App.vue'
// import router from './router'

new Vue({
    // router,
    el:'#app',
    // components:{App},
    // template:`<App></App>`,
 
    // render(createElement){
    //     // console.log(typeof createElement)
    //     // return createElement('h1','你好啊~')
    //     return createElement(App)
    // }
// h是形参,返回值的h(App),h是这个的createElemen函数
    render: h => h(App)
});
上一篇下一篇

猜你喜欢

热点阅读