[英]vue create component from server rendered html
I have a Vue instance already loaded with webpack which loads.vue files properly.我有一个已经加载了 webpack 的 Vue 实例,它可以正确加载.vue 文件。 However there are some files that I cannot use load as some of the html is rendered dynamically from the server.
但是,有些文件我不能使用加载,因为某些 html 是从服务器动态呈现的。
Suppose I have a HTML file with the content below:假设我有一个 HTML 文件,其内容如下:
<div id="test">
<input type="text" :value="message"></input>
</div>
How do I create a vue component with the template above?如何使用上面的模板创建一个 vue 组件?
This was my attempt.这是我的尝试。
const component = new Vue({
name: 'test-component',
el: '#test',
data: {
message: "hello world!"
},
});
What I want rendered is我想要渲染的是
<div id="test">
<input type="text" value="hello world!"></input>
</div>
If neither render function nor template option is present, the in-DOM HTML of the mounting DOM element will be extracted as the template.如果既不呈现 function 也不存在模板选项,则安装 DOM 元素的 in-DOM HTML 将被提取为模板。 In this case, Runtime + Compiler build of Vue should be used.
在这种情况下,应使用 Vue 的 Runtime + Compiler 构建。
---- https://v2.vuejs.org/v2/api/index.html#el ---- https://v2.vuejs.org/v2/api/index.html#el
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.