簡體   English   中英

如何在 SSR Vue/Nuxt 中使用指令設置 InnerText

[英]How to set InnerText with directive in SSR Vue/Nuxt

我想移植我的 vue 指令來渲染服務器端。

客戶端:

mydirective(el,binding,vnode){
    el.innerText = vnode.context.$data.points
}

到目前為止我在 nuxt.config.js 中所做的工作:

render: {
    bundleRenderer: {
      directives: {
        mydirective(node, binding){
             var points = node.context.$data.points //works 
             node.data.style = [{backgroundColor: 'green'}] //works
             node.data.innerText = points  //NOT working
             node.data.textContent = points  //NOT working
        }

我找不到元素參考。

我使用以下函數搜索節點對象:

  Object.keys(node).forEach(key=>{
    console.log(key)
    console.log( node[key])
    console.log('============================%%%%%%%%%%%%%%%%%%%%%================================')
  })
enter code here

找到了:

mydirective(node, binding){
     var points = node.context.$data.points
     node.data.domProps = {
          innerHTML: points
        }
}

文檔: https ://v2.vuejs.org/v2/guide/render-function.html#The-Virtual-DOM

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM