Discovery of using render in Vue

Today, the following error occurred when writing the render method in Vue to select and dye the template

<script>
export default {
    render(h) {
        return h({
            template: '<div>render来渲染结构</div>',
        })
    },
}
</script>

insert image description here

Through Baidu and other means! ! ! Finally found the correct solution, because vue.config.js lacks the runtimeCompiler: true configuration. Sure enough, the configuration will not report errors and can be rendered normally. It’s so amazing that you can’t check the documentation for what it is! Attach the query screenshot of vuecli.
insert image description here
insert image description here
Simply put, vue.loader has parsed the template into js. By default, there will be no runtimeCompiler to reduce the size of the compiled file.
If there is still a template in js, it needs to be opened for parsing.
The last way to write render is to use jsx to write

Guess you like

Origin blog.csdn.net/TwilighTzvz/article/details/127907347