Vue参数传递问题(动态、静态)

 参数传递实际上就是属性绑定 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>组件</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="app">
    <briup-list data="hello"></briup-list>                      //hello
    <briup-list :data="hello"></briup-list>  //取父组件data中的hello属性的值:hello world
    <briup-list :data="'hello world'"></briup-list>             //hello world
    <briup-list data="2"></briup-list>                          //  字符串类型的 2
    <briup-list :data="2"></briup-list
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
v-on:click 动态参数传递是指可以根据组件的具体需求,在触发 click 事件时传递不同的参数。这样可以增强组件的灵活性和复用性。 在 Vue 中,我们可以通过以下方式来实现 v-on:click 动态参数传递: 1. 使用方法调用 通过调用方法来传递参数是最常用的方式。我们可以在方法中定义需要传递的参数,然后在模板中调用方法并传递参数。例如: ```html <template> <button @click="handleClick('hello')">点击我</button> </template> <script> export default { methods: { handleClick(text) { console.log(text) } } } </script> ``` 2. 使用 $event 对象 $event 是 Vue 在事件触发时自动传递的一个参数,它可以获取到当前事件的信息,比如鼠标的位置等。在传递动态参数时,我们可以通过 $event 对象来传递额外的参数。例如: ```html <template> <button @click="handleClick('hello', $event)">点击我</button> </template> <script> export default { methods: { handleClick(text, event) { console.log(text, event) } } } </script> ``` 3. 使用 bind 方法 通过 bind 方法可以将参数绑定到特定的函数中。例如: ```html <template> <button @click="handleClick.bind(this, 'hello')">点击我</button> </template> <script> export default { methods: { handleClick(text) { console.log(text) } } } </script> ``` 总之,通过 v-on:click 动态参数传递,我们可以更加灵活地对组件进行设置,既可以传递静态参数,也可以通过方法调用、$event 对象、bind 方法等方式传递动态参数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值