我不知道如何在挂载组件时提供注入反应数据。我不需要确切的解决办法,只要一点提示就好了。
以下是我的父组件:
@Component
export default class Preferences extends Vue {
@ProvideReactive() serviceLevels: CarrierFilterType[] = [];
// more code here...以下是我的子组件:
@Component
export default class CarrierFilters {
@InjectReactive() readonly serviceLevels!: CarrierFilterType[];
// more code here...这是我的测试文件:
// other imports are here...
import { supportedServiceLevels } from '../../constant';
// initial setup code here...
describe('Settings > Preferences > Content > CarrierFilters.vue', () => {
beforeEach(() => {
options = {
localVue,
i18n,
store,
router,
vuetify: new Vuetify(),
provide: { // I am not sure how to provide the inject-reactive data here...?
serviceLevels: [...supportedServiceLevels],
},
};
initWrapper = shallowMount(CarrierFilters, options);
});
// more code here...目前,当我运行测试时,我会得到以下控制台错误:
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Injection "__reactiveInject__" not found
found in
---> <CarrierFilters>
<Root>顺便说一下,上面的代码使用的是@Inject,而不是@InjectReactive。我看过他们的源代码,似乎我必须以某种方式提供这个密钥__reactiveInject__。
发布于 2022-04-26 20:43:05
将所有的反应性属性放入__reactiveInject__中。例如:
const wrapper = mount(Component, {
localVue,
provide: {
__reactiveInject__: {
foo: "bar"
},
},
});https://stackoverflow.com/questions/71871221
复制相似问题