Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

How to pass parameters into the function? #16

Closed
slmjkdbtl opened this issue Aug 15, 2015 · 8 comments
Closed

How to pass parameters into the function? #16

slmjkdbtl opened this issue Aug 15, 2015 · 8 comments

Comments

@slmjkdbtl
Copy link

v-touch="press: func()" => func() will be excuted after the page is loaded, and the press event is not working.
but v-touch="press: func" works fine.

Then how to pass parameters?

@herbertpimentel
Copy link

I have been using like so, but I am really curious about it and maybe that way I do is not a good practice.

<ul v-for="pessoa in pessoas">
  <li>
    <a href="#" v-on:click="showPessoa(pessoa)">{{ pessoa.nome }}</a>
  </li>
</ul>
    // ...
    methods : {
        showPessoa : function(pess){
            console.log(pess);
            alert(pess.nome);
        }
    }

@kamifun
Copy link

kamifun commented Nov 7, 2016

If you not need the $event argument,you can do this:
v-touch:press="func.bind(this, arg)"

@AdrianKuriata
Copy link

AdrianKuriata commented Jun 9, 2017

Hi, i have something like this:

v-on:click="removeRelation({{$people->id}}, relation.people['id'])"

I have a problem with get a target from this. This is my function for Vue:

removeRelation: function($peopleId, $relatedId) {
		//do something
	}

Is possible to get clicked element with arguments? I tried add this to html v-on:click like a third argument and try to display it with thirdArgument.target, but i getting undefined into console. (I working with laravel, {{$people->id}} is PHP variable and i normally can display this attributes into removeRelation function).

//Edit

Nevermind, needed add $event like a attribute:
Vue - Methods in Inline Handlers

@bognix
Copy link

bognix commented Jul 5, 2017

Something like this worked for me just fine.

<foo @click="(event) => { myFunction(event, myArgument) } ></foo>

Hope it helps

@AdrianKuriata
Copy link

@bognix this is not clear code, check post before your, i added solution.

@bognix
Copy link

bognix commented Jul 5, 2017

cool! thanks for posting, I missed the link

@wu08518
Copy link

wu08518 commented Jan 18, 2018

understand

1 similar comment
@fahadqadeer1
Copy link

understand

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants