问题描述
我有两个不同的HTML视图,希望使用相同的ts文件。有没有办法在像波纹管这样的条件下加载它们
@Component({
selector: "otk-specification",templateUrl: templateUrl: Responsive ? "./specification-responsive.component.html" : "./specification.component.html",})
export class SpecificationComponent implements OnInit{}
或例如,将此ts加载到响应组件
解决方法
我通过从基础ts扩展来解决它。 为从第一个延伸的第二个视图制作ts文件
class TechnologySummary extends Component {
state = {
link: true,technologySeoName: null
}
componentDidMount() {
if(this.state.link){
this.props.onLoadTechnology(this.state.technologySeoName);
}
}
constructor(props) {
super(props);
let technologySeoName = null;
technologySeoName = props.match.params.techName;
console.log('technologySeoName',technologySeoName);
this.state.technologySeoName = technologySeoName;
}
render() {
return <Display technology={this.props.technology}
deleteVersion={this.deleteVersion}/>;
}
}
const mapStateToProps = state => {
return {
technology: state.technology.technology
};
};
const mapDispatchToProps = dispatch => {
return {
onLoadTechnology: (technologySeoName) => dispatch(actions.onLoadTechnology(technologySeoName)),onDeleteTechnology:(id) => dispatch(actions.onDeleteTechnology(id))
};
};
export default connect(mapStateToProps,mapDispatchToProps)(TechnologySummary);