⊗jsvuPmBsMPP 13 of 72 menu

Passing Parameters to a Method in Vue

You can pass parameters to methods that are bound as handlers. Let's see in practice. Let's say we have the following method that takes a message as a parameter that needs to be output:

methods: { show: function(str) { alert(str); } }

Let's bind this method to different tags, passing it the text to be output as a parameter:

<template> <button @click="show('text1')">btn1</button> <button @click="show('text2')">btn2</button> </template>

Create a method that will take a number as a parameter and output the square of this number through alert.

Make two buttons. When you press the first button, print the square of 2, and when you press the second button, print the square of 3.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline