htmlでvue-routerを使用する


vueとvue-routerの導入
<script src="https://unpkg.com/vue/dist/vue.js">script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js">script>

完全な例

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>
    <script src="https://unpkg.com/vue/dist/vue.js">script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js">script>
head>
<body>
    <div id="app">
        <h1>Hello !h1>
        <p>
          
          
          
          <router-link to="/hash1">   com1router-link>
          <router-link to="/hash2">   com2router-link>
        p>
        
        
        <router-view>router-view>
        
        
        
        
        
        
        
    div>
body>
<script>
    // 1.   (  )  。
    const com1 = { template: '
1
'
} const com2 = { template: '
2
'
} // 2. // 。 "component" Vue.extend() // , , . const routes = [ { path: '/hash1', component: com1 }, { path: '/hash2', component: com2 } ] // 3. router , `routes` const router = new VueRouter({ routes // ( ) routes: routes }) // 4. 。 // router , const app = new Vue({ router }).$mount('#app');//el ,mount ( )
script> html>