du4010 2016-10-13 18:02
浏览 13
已采纳

Laravel 5.3和Vue 2

I'm playing with Vue 2 in a new Laravel 5.3 app, and I'm not sure how to bind a URL in the laravel format.

I have some config rows pulled from a DB, and I want to simply loop over them displaying the data, and then present a button to take you to an edit screen. Vue doesn't support simply interpolating the config row's ID in the URL as I'm looping over the rows using:

<tr v-for="config in data">
  <td>
    <a href="/configurations/{{ config.id }}/edit">{{ config.name }}</a>
  </td>
</tr>

The Vue docs say to bind to another function like this:

<a v-bind:href="url">

and then I have a url method defined like this:

export default {
    mounted() {
        console.log('Component ready.')
    },
    data: function () {
        return {
            data: [config data array]
        }
    },
    computed: {
        url: function () {
            console.dir(this); // the whole component, not the row
            console.dir(this.id); // undefined
            console.dir(this.config); // undefined
            return "/configurations/" + this.config.id + "/edit" // throws error
        }
    }
}

I can't seem to get the returned URL to render, it normally either throws an error or complains that my var is undefined.

How do I complete this (simple) task?

  • 写回答

1条回答 默认 最新

  • dth62818 2016-10-13 18:36
    关注

    The solution was to ignore the computed URL function and just do the following: <a :href="'/configurations/' + config.id + '/edit'">

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效