Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue父组件在子组件传递的参数中增加参数--2019-01-11 #21

Open
lizhongzhen11 opened this issue Jan 11, 2019 · 0 comments
Open

Comments

@lizhongzhen11
Copy link
Owner

虽然我们日常大多数会用element-ui或者iview等等ui框架,但是总有些业务场景,我们需要在子组件传递给我的参数中增加一些参数进行判断等等,那么该怎么写呢?
其实之前有百度查到过,但一段时间不写或者项目很忙大脑转不过来时就容易忘,所以记录下。
具体看:vuejs/vue#5735
举个例子:
子组件

<template>
  <div>
    <input @change="change"/>
  </div>
</template>
<script>
export default {
  name: 'child',
  methods: {
    change (e) {
      this.$emit('input', e)
    }
  }
}
</script>

父组件:

<template>
  <div>
    <child @input="value => input(value, 新参数)"/>
  </div>
</template>
<script>
import Child from './child'
export default {
  name: 'parent',
  components: {child}
  methods: {
    input (value, 新参数) {
      console.log(value, 新参数)
    }
  }
}
</script>
@lizhongzhen11 lizhongzhen11 changed the title vue父组件在子组件传递的参数中增加参数 vue父组件在子组件传递的参数中增加参数--2019-01-11 Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant