2017-04-02 41 views
0

所以在我nuxt.js项目,我需要在此描述https://nuxtjs.org/examples/custom-routesnuxt.js - >自定义路线不爱可信如何获得“身份证”

我迄今implmented是下面的自定义路线。

文件:网页\ trails.vue

... 
<nuxt-link v-bind:to="'/trail/' + trail.article_code">{{ trail.article_description }}</nuxt-link> 
... 

这将equivelent到index.vue文件。如果我是正确的没有额外的代码是在这个文件是有关

文件:\网页线索\ _id

<template> 
    <div class="vttTrails"> 
     <div class="ui grid centered"> 
      <div v-for="(trail, index) in listTrail"> 
       <div class="ui card"> 
        {{ trail.article_code }} 
       </div> 
      </div> 
     </div> 
    </div> 
</template> 

<script> 
    import feathers from 'feathers/client'; 
    import socketio from 'feathers-socketio/client'; 
    import hooks from 'feathers-hooks'; 
    import io from 'socket.io-client'; 
    import * as process from "../../nuxt.config"; 

    const vttSocket = io(process.env.backendUrl); 
    const vttFeathers = feathers() 
     .configure(socketio(vttSocket)) 
     .configure(hooks()); 

    const serviceArticles = vttFeathers.service('articles'); 

    export default { 
     layout: 'default', 
     data: function() { 
      return { 
       listTrail: [], 
       curLanguage: this.$store.state.site.curLanguage, 
       curCategory: this.$store.state.site.curCategory 
      } 
     }, 
     mounted: function() { 
      return serviceArticles.find({ 
       query: { 
        category_id: this.$store.state.site.curCategory, 
        article_code: '', 
        $sort: { 
         article_rating: 1 
        }, 
        $select: [ 
         'id', 
         ['article_description_' + this.$store.state.site.curLanguage, 'article_description'], 
         'article_length', 
         'article_ascend', 
         'article_code', 
         'article_at', 
        ] 
       } 
      }).then(page => { 
       this.listTrail = page.data; 
      }) 
     }, 
    } 
</script> 

所以在这里,我把整个文件,以防万一。点击链接将转到例如“trail \ cwu”这是正确的,因为我有这个。值“cwu”需要进入article_code: ''。我试图做mounted: function(params)但它不起作用。

问题

什么我需要做我的“_id.vue”,让“PARAMS”的一部分?最终我会调整选择,因为它只会返回一个选项。

回答

0

好的。所以我现在做的是改变'_id.vue'文件中的数据函数。它现在包含:

data: function() { 
      return { 
       listTrail: [], 
       curLanguage: this.$store.state.site.curLanguage, 
       curCategory: this.$store.state.site.curCategory, 
       curTrail: window.location.pathname.split('/')[2] 
      } 
     }, 

它可能不是正确的方法,但它确实有效。