Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change route with vue- <router-link>

I have a <router-link to = "/ endreco / test">, but I need to perform the same behavior on a vue-material tab, something like this: <md-tab md- icon = "books"> .. to change my route, same as the href = ""

What should I do?

I'm using vue.js, the vue-router to control routes and style with vue-material

like image 733
Rafael Alves Avatar asked Sep 08 '17 18:09

Rafael Alves


2 Answers

You can add a @click.native handler to push to a route manually (the .native modifier is needed since the md-tab component does not have a click event):

<md-tab @click.native="$router.push('/endreco/test')">

Here's the documentation on Programmatic Navigation with Vue Router.

like image 147
thanksd Avatar answered Sep 30 '22 05:09

thanksd


See my code I have implemented a method which traverses to router to see routes of mentioned name of component, you can easily get idea!

<template>
  <div>
    <div class="mdl-grid">
      <div class="mdl-cell mdl-cell--3-col mdl-cell mdl-cell--1-col-tablet mdl-cell--hide-phone"></div>
      <div class="mdl-cell mdl-cell--6-col mdl-cell--4-col-phone">
        <div class="image-card" v-for="picture in this.pictures" @click="displaydetails(picture.id) ">
          <div class="image-card__picture">
            <img :src="picture.url" />
          </div>
          <div class="image-card__comment mdl-card__actions">
            <span>{{ picture.comment }}</span>
          </div>
        </div>
      </div>
    </div>
    <router-link class="add-picture-button mdl-button mdl-js-button mdl-button--fab mdl-button--colored" to="/postview">
      <i class="material-icons">add</i>
    </router-link>
  </div>
</template>
<script>
import data from '../data'
export default {
 data() {
     return{
         'pictures' : data.pictures 
     }
 },
 methods :{
     displaydetails (id){
         this.$router.push({name:'detailview', params:{id:id}});
         console.log("helo");
     }
 }
}
</script>

Hope get something resourceful out of it!

like image 31
Meet Zaveri Avatar answered Sep 30 '22 06:09

Meet Zaveri