【发布时间】:2018-10-05 07:26:10
【问题描述】:
我没想到会很艰难。
我有一个像
这样写的子组件InputWrapper.vue
<script>
import StyledInput from "./input";
export default {
name: "MyInput",
props: {
multiline: Boolean,
onChange: Function
},
render(h) {
const { multiline, onChange } = this;
console.log(onChange);
return (
<div>
<StyledInput multiline={multiline} onChange={e => onChange(e)} />
</div>
);
}
};
</script>
然后我将实际输入作为 vue-styled-components 作为 Input.js。对于那些熟悉样式化组件的人,无需解释该代码。
然后我在我的父组件 Home.vue 中使用这个 InputWrapper 组件
<template>
<div class="pLR15 home">
<Row>
<MyInput :multiline="true" placeholder="Sample Input" type="text" :onChange="handleChange"></MyInput>
</Row>
</div>
</template>
<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
import Row from "@/ui_components/row";
import MyInput from "@/ui_components/form/input/index.vue";
export default {
name: "home",
components: {
HelloWorld,
Row,
MyInput
},
methods: {
handleChange: function(e) {
console.log("Hey you are changing my value to", e.target.value);
}
}
};
</script>
问题 - 未触发父级的 onChange。
【问题讨论】:
标签: javascript vue.js vuejs2