vue.js - 如何使用与主应用程序相同的 vue 实例安装 vue 插件
问题描述
使用vue-sfc-rollup创建的 Vue 组件有这部分安装代码,我无法访问。
// To auto-install on non-es builds, when vue is found
// eslint-disable-next-line no-redeclare
/* global window, global */
if ('false' === process.env.ES_BUILD) {
let GlobalVue = null;
if (typeof window !== 'undefined') {
GlobalVue = window.Vue;
} else if (typeof global !== 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
GlobalVue = (global as any).Vue;
}
if (GlobalVue) {
// ***********
//
// NEVER REACH
//
// ***********
(GlobalVue as typeof _Vue).use(plugin);
}
}
我试过这个
const global: any = window
global.Vue = Vue
或这个
const global: any = window
const vm = new Vue({
render: (h): VNode => h(Dev),
}).$mount('#app');
global.Vue = vm
但是安装插件时全局 vue不可用
我问是因为如果我在插件中使用类组件
@Component
export default class TheComponent extends Vue {
然后我在主应用程序中收到此警告:
vue.runtime.esm.js
[Vue 警告]:$attrs 是只读的。
[Vue 警告]:$listeners 是只读的。
我认为这是因为该组件安装在 vue 的不同实例上。
编辑:当然我以这种方式安装插件
Vue.use(TheComponent)
解决方案
推荐阅读
- chromecast - 使用自定义 CAF Google Cast 接收器,如何在每个 DRM 许可证请求之前执行异步操作?
- ubuntu - 对 Xubuntu 的 ping 感到好奇
- caching - 将 redis 缓存与 EF Core 一起使用
- r - 有人可以为我分解第 4 行代码吗?这是在 R
- shopify - 在 Shopify 中,当用户未登录时,我如何访问用户 ID(或匿名 ID)?
- python - 使用 zip() 和 join() 等内置 python 函数对我的函数性能有什么开销?
- python - 如何将自定义值从 DRF ModelViewSet 传递到权限类?
- c# - Visual Studio 2019 xUnit 测试错误 CS0246
- javascript - 我可以将基于 Node 的项目迁移到 Deno 吗?
- postgresql - 如何有效地计算分类属性的类别(250)?PostgreSQL 或 Python