在React中,我们可以以这种方式添加动态组件(我从react https://reactjs.org/docs/jsx-in-depth.html中获取它):
import React from 'react';
import { PhotoStory, VideoStory } from './stories';
const components = {
photo: PhotoStory,
video: VideoStory
};
function Story(props) {
const SpecificStory = components[props.storyType];
return <SpecificStory story={props.story} />;
}
它只是一个返回带有正确组件的模板的函数(取决于道具)。
在Vue中,我们可以使用以下方法执行相同的逻辑:
<template>
<component :is="currentComponent"></component>
</template>
currentComponent将是一个计算属性(通常)或数据中的一个属性。
我的问题是:在性能和渲染方面,有什么更便宜的选择?
发布于 2020-01-22 10:14:55
如果您想动态加载组件,那么您将使用计算属性,因为属性值是动态的,应该处于状态,我猜您正在使用vuex对计算属性使用...mapGetters检索数据。
使用数据属性主要用于固定值或声明。
https://stackoverflow.com/questions/59473464
复制相似问题