有没有办法在 nuxt js 中编写自定义指令,它适用于 ssr 和前端(甚至仅适用于 ssr)?
我在以下文档中尝试过它: https ://nuxtjs.org/api/configuration-render#bundleRenderer
所以我添加了这段代码:
module.exports = {
render: {
bundleRenderer: {
directives: {
custom1: function (el, dir) {
// something ...
}
}
}
}
}
到 nuxt.config.js
然后我在模板中使用它作为:
<component v-custom1></component>
但它不起作用,它只是抛出前端错误
[Vue 警告]:无法解析指令:custom1
而且它似乎甚至在服务器端也不起作用。
感谢您的任何建议。
原文由 Martin Rázus 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 nuxt-edge 中测试(它的 nuxt 2.0 将在本月或下个月推出,但它目前非常稳定)。
nuxt.config.js
页面.vue
从服务器生成的 html: