【发布时间】:2025-12-09 19:20:04
【问题描述】:
我创建了支持 vue 的自定义节点模块。
Package.json
{
"name": "test-node-module",
"version": "1.0.0",
"description": "",
"main": "./dist/index",
"scripts": {
"dev": "vue serve test.vue",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Sam",
"license": "ISC",
"devDependencies": {
"@vue/compiler-sfc": "^3.0.0-beta.15",
"bili": "^5.0.5",
"rollup-plugin-vue": "^6.0.0-beta.6",
"vue-template-compiler": "^2.6.11"
}
}
index.js
import test from "./test.vue"
export default {
install(Vue, options) {
Vue.component("test", test);
}
}
test.vue 有简单的文字。
在我项目的 main.js 中
import Test from "test-node-module"
Vue.use(Test)
使用组件<test></test> 会出现这样的错误。
[Vue warn]: Error in render: "TypeError: vue.openBlock is not a function"
在自定义节点结节中,dist/index.js 文件是这样的。
'use strict';
var vue = require('vue');
var script = {};
function render(_ctx, _cache) {
return (vue.openBlock(), vue.createBlock("div", null, " Test123 ")) // Error is here...
}
script.render = render;
var index = {
install: function install(Vue, options) {
Vue.component("test", script);
}
};
module.exports = index;
我该如何解决这个问题?我错过了什么吗?
【问题讨论】:
标签: javascript vue.js node-modules