简体   繁体   English

如何从vue js模板中将params传递给方法调用?

[英]How to pass params into method call from within vue js template?

So inside my template I have the following: 所以在我的模板中我有以下内容:

          <template v-for="item in jobs">
            <tr>
                <td v-for="stage in item.stage_execs" :style="getStyle(stage.status.name)" :title="stage.exec_node.name" >
                  <b><a :href="[[ item.mongo_link ]]/[[stage.name]]">[[ stage.name ]]</a></b>
                  <br>
                  [[ stage.duration_millis | durationReadable  ]]
                  <br>
                  [[ stage.status.name ]]
                </td>
            </tr>
          </template>

The problem is I am trying to create a href link with two variables, but I don't think I can do that in vue.js 问题是我试图用两个变量创建一个href链接,但我不认为我可以在vue.js中这样做

I'm hoping there IS a way to do this and I just don't know about it, otherwise I can just write a method to create the link and call it like: 我希望有一种方法可以做到这一点,我只是不知道它,否则我只能编写一个方法来创建链接并调用它:

<a :href="[[ generateMongoLink ]]">

The question I have (if I have to go this route) is how do I pass two params into the method from this call above? 我有的问题(如果我必须走这条路)是如何通过上面的调用将两个参数传递给方法? I want to call with item.mongo_link and stage.name 我想用item.mongo_link和stage.name调用

I think you should change: 我认为你应该改变:

<a :href="[[ item.mongo_link ]]/[[stage.name]]">

to

<a :href="`${item.mongo_link}/${stage.name}`">

A bit cleaner way is using methods 更清洁的方法是使用方法

methods: {
    generateMongoLink(item) {
     return item.mongo_link + '/' + stage.name"
   }
 }

Then in template 然后在模板中

<a :href="generateMongoLink(item)">

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

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