此处的组件切换使用的是Vue
中的component
组件中的is
属性来实现的。该is
属性实现的功能是根据组件名称的不同来切换显示不同的组件控件。
示例
源码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>组件</title>
</head>
<body>
<template id="demo1">
<h2>组件1</h2>
</template>
<template id="demo2">
<h2>组件2</h2>
</template>
<div id="app">
<a href="javascript:void(0)" @click="componentName = 'demo1'">组件1</a> |
<a href="javascript:void(0)" @click="componentName = 'demo2'">组件2</a>
<component :is="componentName"></component>
</div>
<script sr