Does vue introduce vue files so dynamically?

I need to introduce a new vue file when the vue project is running, which is generated by the server and requested back through ajax. How can I achieve this function?

Mar.01,2021

vue-router has a lazy loading function , it is impossible for you to parse vue files directly with js
but what you can do is to split the code into multiple pieces after packaging and load


when needed.

Uh

that. I just noticed the .vue file. Vue file is not very feasible, because the vue file itself is compiled by webpack processing such as vue-loader, otherwise there is no way to identify problems including templates, styles, es6 syntax, and so on. But if the vue instance can be written in the following way, and the template can be written with the render function and then mounted dynamically, there should be no problem

update again.

I just read the introduction of vue's official website. Runtime+Compiler, can realize template direct html without using render,. You can study
ide/installation.html-sharp%E8%BF%90%E8%A1%8C%E6%97%B6-%E7%BC%96%E8%AF%91%E5%99%A8-vs-%E5%8F%AA%E5%8C%85%E5%90%AB%E8%BF%90%E8%A1%8C%E6%97%B6" rel=" nofollow noreferrer "> vue compiler
vue-el
what can be achieved in theory can be seen on vue's official website api,. Vue.extend introduction
my demo

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
    

{{ message }}

<input type="text" v-model="message"/> <button @click="dynamicMount">vue</button> <div id="mount-point"> </div> </div> <script> new Vue({ el: '-sharpapp', data: { message:'Hello World!' }, created() { this.dynamicMount = function() { let Profile = Vue.extend({ template: '

{{firstName}} {{lastName}} aka {{alias}}

', data: function () { return { firstName: 'Walter', lastName: 'White', alias: 'Heisenberg' } } }) // Profile new Profile().$mount('-sharpmount-point') } } }) </script> </body> </html>

that depends on whether the requested file has any other special syntax. If it is only html syntax and css syntax, vue syntax, there is no problem. If the content of the request file is a component, then read out the contents of the file and directly assign the value to the page script tag, or assign the html code directly to the template variable in vue.extend.

Menu