Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将VNode呈现为html字符串_Javascript_Vue.js - Fatal编程技术网

Javascript 将VNode呈现为html字符串

Javascript 将VNode呈现为html字符串,javascript,vue.js,Javascript,Vue.js,我正在开发一个Vue服务器端模板引擎,包的一部分包括一个头部管理系统 我正在为Vue开发一个服务器端渲染器,为了让SSR的头部管理工作,它需要一种将VNodes渲染为文本的方法 我的问题: 如何将VNode渲染为字符串?例如: this.$ssrContext.head=rendervNodesString(this.$slots.head) 示例用例: master.vue <template> <div id="app"> <slot n

我正在开发一个Vue服务器端模板引擎,包的一部分包括一个头部管理系统

我正在为Vue开发一个服务器端渲染器,为了让SSR的头部管理工作,它需要一种将
VNode
s渲染为文本的方法

我的问题: 如何将VNode渲染为字符串?例如:

this.$ssrContext.head=rendervNodesString(this.$slots.head)

示例用例:

master.vue

<template>
    <div id="app">
        <slot name="content"></slot>
    </div>
</template>
<script>
export default {
    created: function(){
        if(this.$isServer){
            var VNodesToRender = this.$slots.head
            this.$ssrContext.head = 'rendered VNode here'
        }
    }
}
</script>
<template>
    <master>
        <template slot="content">
            Hello World
        </template>
        <template slot="head">
            <script src="https://unpkg.com/vue/dist/vue.js"></script>
            <title>Hello</title>
        </template>
    </master>
</template>
<script>
import master from "layouts/master.vue"

export default {
    components: {
        master
    }
}
</script>
我的目标是将
home.vue
head
槽渲染成字符串,并将其注入
this.$ssrContext
以便可以在服务器端读取和注入

master.vue
中,我可以毫无问题地访问
this.$slots.head
,它包含正确的
VNode
s

使用字符串的位置

{{{head}}}

const renderer = createBundleRenderer(bundle.server, {
    runInNewContext: false,
    inject: false,
    template: `<!DOCTYPE html>
        <html>
            <head>
                {{{ head }}}
                {{{ renderResourceHints() }}}
                {{{ renderStyles() }}}
            </head>
            <body>
                <!--vue-ssr-outlet-->
                <script>${ bundle.client }</script>
            </body>
       </html>`
})
const renderer=createBundleRenderer(bundle.server{
runInNewContext:false,
注:错,
模板:`
{{{head}}}
{{{renderResourceHitts()}}}
{{{renderStyles()}}}}
${bundle.client}
`
})
注意: 这个问题不像:


  • 因为它需要一个字符串输出,然后将其传递给SSR

    ,我想您需要的是。它可能是
    vue服务器渲染器
    包。似乎可以渲染任何东西。@哦,很不幸,这没什么帮助。我已经在使用它来渲染.vue文件。我正在尝试将一个变量从.vue文件传递到$ssrContext