2017-02-14 6 views
2

Вот моя JavaScript/vue.js код:Использование V-привязки поместить данные в тег в свойстве HREF (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 
        }) 
       } 
      } 
    } 

А вот это мои 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> 

Я попытался поместить некоторые данные в раздел href моего тега a, чтобы ссылаться на другую страницу, но он не работает.

ответ

0

Попробуйте следующее:

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

При использовании this.href он начнет собирать href из данных ви, например,

+0

Спасибо, с предложением код работал. ;) –