2017-02-14 3 views
2

Hier ist meine javascript/vue.js Code:v-bind Unter Verwendung von Daten in einem Tag ein in der Eigenschaft href zu setzen (VUE.JS 2 + Laravel 5.3)

 import _ from 'lodash' 
     export default{ 
      props:['campanha'], 
      data(){ 
       return{ 
        list:[], 
        filter: '', 
        href: '/campanha/9/edit' 
       } 
      }, 
      methods:{ 
       url: function (href){ 
        return '/campanha/'+this.href+'/edit' 
       } 
      }, 
      mounted: function(){ 
       this.list = JSON.parse(this.campanha) 
      }, 
      computed: { 
       filteredCampanhas(){ 
        var self = this 
        return this.list.filter(function(campanhas) { 
         return campanhas.nome.indexOf(self.filter) > -1 
        }) 
       } 
      } 
    } 

Und hier `s mein html:

<template> 
     <div> 
      <div class="well"> 
       <a href="campanha/create" class="btn btn-default" title="Nova Campanha">Novo Cadastro <span class="glyphicon glyphicon-plus" aria-hidden="true"/></a><br></br> 
       <input type="text" class="form-control" placeholder="Filtrar Campanhas" v-model="filter"> 
      </div> 
      <div class="table-responsive"> 
       <table class="table table-borderless"> 

        <thead> 
         <tr> 
          <th>Id</th> 
          <th>Nome</th> 
          <th>Data Início</th> 
          <th>Data Término</th> 
          <th>Hora Inícío</th> 
          <th>Hora Término</th> 
         </tr> 
        </thead> 
        <tbody> 

         <!--{{ url('/campanha/' . $item->id_campanha . '/edit') }} 

         href: '/campanha/9/edit' 
          <td><a v-bind:href="href">{{ c.nome }}</a></td> 
         !--> 

         <tr v-for="c in filteredCampanhas"> 
          <td>{{ c.id_campanha }}</td> 
          <td><a :href="url(c.id_campanha)">{{ c.nome }}</a></td> 
          <td>{{ c.data_inicio }}</td> 
          <td>{{ c.data_termino }}</td> 
          <td>{{ c.hora_inicio }}</td> 
          <td>{{ c.hora_termino }}</td> 
         </tr> 

        </tbody> 

       </table> 
      </div> 
     <div> 


</template> 

Ich habe versucht, einige Daten in den href-Abschnitt meines Tags einzufügen, um auf eine andere Seite zu verlinken, aber es funktioniert nicht.

Antwort

0

Versuche folgende:

methods:{ 
    url: function (href){ 
     return '/campanha/'+ href+'/edit' 
    } 
}, 

Wenn Sie this.href verwenden wird es beginnen href von Daten von vue Instanz zu holen,

+0

Danke, mit Ihrem Vorschlag des Code gearbeitet. ;) –

Verwandte Themen