vue.js - 汇总生成的 vue 组件未作为自定义 vue 标签调用
问题描述
我在关注这个例子:
https://vuejs.org/v2/cookbook/packaging-sfc-for-npm.html
我想用这个 html 渲染一个名为“flex-text”的 vue 自定义标签:
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>runtime</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
<script src="/lib/mk-vue-flex-text.js"></script>
</head>
<body>
<flex-text
name="test"
value="text"></flex-text>
</body>
</html>
正在加载“/lib/mk-vue-flex-text.js”的 javascript 代码(说真的,我已经检查过了)。
我的包装代码(基于)如下所示:
import component from '../src/mk-vue-flex-text.vue';
export function install(Vue) {
if (install.installed) return;
install.installed = true;
Vue.component('flex-text', component);
}
const plugin = { install };
// Auto-install when vue is found (eg. in browser via <script> tag)
let GlobalVue = null;
if (typeof window !== 'undefined') {
GlobalVue = window.Vue;
} else if (typeof global !== 'undefined') {
GlobalVue = global.Vue;
}
if (GlobalVue) {
GlobalVue.use(plugin);
}
// To allow use as module (npm/webpack/etc.) export component
export default component;
vue-Component 似乎已正确转换为“mk-vue-flex-text.js”:
var FlexText = (function (exports) {
'use strict';
// lots of stuff etc.
// ...
// generated app code
// ...
// Import vue component
// Declare install function executed by Vue.use()
function install(Vue) {
if (install.installed) { return; }
install.installed = true;
Vue.component('flex-text', __vue_component__);
}
// Create module definition for Vue.use()
var plugin = {
install: install,
};
// Auto-install when vue is found (eg. in browser via <script> tag)
var GlobalVue = null;
if (typeof window !== 'undefined') {
GlobalVue = window.Vue;
} else if (typeof global !== 'undefined') {
GlobalVue = global.Vue;
}
if (GlobalVue) {
GlobalVue.use(plugin);
}
exports.default = __vue_component__;
exports.install = install;
return exports;
}({}));
所以,在我看来一切都很好。但是组件仍然没有被渲染。
解决方案
推荐阅读
- python - 如果它在pycharm中工作,如何修复'modulenotfounderror'?
- reactjs - JSX 的 Typescript 设置类型注解
- angular - 使用rest api重定向到url的问题
- kotlin - Kotlin 中的 Android RecyclerView
- swift - 如何在 Swift 中配置小型服务器?
- xml - 如何使用 Visual Studio 2017 创建项目组模板
- android - Android:从本地数据库读取时处理错误情况?
- kernel-module - 如何通过按钮连接到 gpio 来控制背光?
- c# - 创建多个自定义发票(自费和第三方付款人)
- angular - 错误消息:无法调用类型缺少调用签名的表达式