Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .active {color: red;}
  </style>
</head>
<body>
  <div id="app">
    <router-view></router-view>
  </div>
  <script crossorigin="anonymous" integrity="sha384-+jvb+jCJ37FkNjPyYLI3KJzQeD8pPFXUra3B/QJFqQ3txYrUPIP1eOfxK4h3cKZP" src="https://lib.baomitu.com/vue/2.6.11/vue.js"></script>
  <script crossorigin="anonymous" integrity="sha384-+Asl5rl/8/miQUCzICBPdaU116UU0E8qRK2yW+GGWm9Gl5amVsmF59QiSnOnFxv7" src="https://lib.baomitu.com/vue-router/3.1.3/vue-router.js"></script>
  <script>
    const List = Vue.component('List', {
      template: `
        <div>
          <nav @click="toggleTab">
            <span :class="{active: tab=='hot'}" data-tab="hot">热门</span>
            <span :class="{active: tab=='question'}" data-tab="question">问题</span>
            <span :class="{active: tab=='video'}" data-tab="video">视频</span>
            <span :class="{active: tab=='consulting'}" data-tab="consulting">咨询</span>
          </nav>
          <router-link to="/detail">detail page</router-link>
        </div>
        `,
      computed: {
        tab() {
          return this.$route.query.tab || 'hot'
        },
      },
      methods: {
        toggleTab(e) {
          this.$router.replace({query: {tab: e.target.dataset.tab||'hot'}});
        }
      },
    });
    const Detail = Vue.component('Detail', {
      template: '<p>this is detail page</p>'
    })
    const router = new VueRouter({
      routes: [
        {path: '/', redirect: '/list'},
        {path: '/list', component: List},
        {path: '/detail', component: Detail}
      ]
    })
    var vm =new Vue({
      el: '#app',
      router,
    })
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers