[Quick App] The event object and custom parameters are passed at the same time, and the event object cannot be received correctly.

 【Key words】

Event binding, custom parameters, event object

【Problem background】

In the quick app, the event method of the component is bound in the following way, and the event object and custom parameters are passed at the same time. It is found that the event object is not correctly received in the callback method.

The problem code is as follows:

<template>

  <!-- Only one root node is allowed in template. -->

  <div class="container">

    <input id="input1" type="button" value="跳转" "jump(event,1)"/>

  </div>

</template>

<script>

  module.exports = {

    jump: function (event, v) {

      console.info("e = " + JSON.stringify(event));

      console.info("v = " + v);

    },

  }

</script>

screenshot

cke_787.png

【problem analysis】

In the above code, jump(event, 1) does not need to bring the event event object, because when the callback function is called, an evt parameter will be automatically added at the end of the parameter list, and the context data related to the callback event can be accessed through the evt parameter.

【Solution】

Modify the code as follows:

<template>

  <!-- Only one root node is allowed in template. -->

  <div class="container">

    <!—把问题代码中jump(event,1)修改为jump(1)-->

    <input id="input1" type="button" value="跳转" "jump(1)" />

  </div>

</template>

<script>

  module.exports = {

    jump: function (v, evt) {

      console.info("e = " + JSON.stringify(evt));

      console.info("v = " + v);

    }

  }

</script>

The modified operation log is as follows:

cke_2562.png

Guess you like

Origin blog.csdn.net/Mayism123/article/details/132077852