繁体   English   中英

使用v-bind将数据放入属性href(VUE.JS 2 + Laravel 5.3)中的标签a中

[英]Using v-bind to put data into a tag a in the property href (VUE.JS 2 + Laravel 5.3)

这是我的javascript / vue.js代码:

        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>

我试图将一些数据放入标签a的href部分中,以链接到另一个页面,但是它不起作用。

请尝试以下操作:

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

当您使用this.href ,它将开始从vue实例的数据中选择href

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM