JSFiddle - React, Tailwind, and code Playground

by educkf

HTML

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

<div id="app">
  <h1>Hello App!</h1>
  <ul>
    <li :class="isActive('foo')">
      <router-link to="/foo">Go to Foo</router-link>
    </li>
    <li :class="isActive('bar')">
      <router-link to="/bar">Go to Bar</router-link>
    </li>
  </ul>

  <router-view></router-view>
</div>

CSS

li.active {
  font-weight: bold;
}

li a {
  text-decoration: none;
  color: black;
}

JavaScript

const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }

const routes = [
  { path: '/foo', name: 'foo', component: Foo },
  { path: '/bar', name: 'bar', component: Bar }
]

const router = new VueRouter({
  routes
})

const app = new Vue({
  el: '#app',
  router,
  data: {
    message: 'Hello Vue!'
  },
  methods: {
  	isActive: function(path) {
    	if (this.$route.name == path) {
      	return 'active';
      }
    }
  }
});