我想将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
答案 0 :(得分:0)
找到了:
mydirective(node, binding){
var points = node.context.$data.points
node.data.domProps = {
innerHTML: points
}
}
文档:https://vuejs.org/v2/guide/render-function.html#The-Virtual-DOM