ui-input 里的值要怎么得到?
顺便抱怨一句:
找不到uikit的文档,官方只有例子,没有例子的源码。。。。。
<ui-input @change='_onValueChange' ></ui-input>
// 当 ui-input 数值发生变化的时候,会触发 change 事件
_onValueChange (event) {
let value = event.target.value;// input 的数值
}
可以通过这样去获取 ui-input 的数值
有什么办法用 .value 来取吗? 我试了 this.$input_test.value 不行。
input_test 是这个ui-input的id
_onValueChange 这个函数会报错
SyntaxError: Unexpected token {
at eval ()
at Object.s (D:\CocosCreator_2.2.0\resources\app.asar\editor-framework\lib\renderer\ui\utils\resource-mgr.js:1:933)
at D:\CocosCreator_2.2.0\resources\app.asar\editor-framework\lib\renderer\ui\utils\dock-utils.js:1:7050
at D:\CocosCreator_2.2.0\resources\app.asar\editor-framework\lib\renderer\ui\panel\frame.js:1:2105
这么写:
this.$input_test.addEventListener(‘change’, (event, target) => {
Editor.log(“value 111=” + event + ", target = " + target);
});
输出
value 111=[object CustomEvent], target = undefined
也得不到值
给一下你现在的写法
template 里:
![]()
定义:
input_test: ‘#input_test’,
ready (): 这下面两种写法都拿不到值
this.$input_test.addEventListener(‘change’, (event, target) => {
Editor.log(“value 111=” + event + ", target = " + target);
});
this.$input_test.addEventListener('confirm', () => {
Editor.log("this.$input_test: 111=" + this.$input_test);
Editor.log("this.$input_test: 222=" + this.$input_test.value);
});
用这个试看看
this.$input_test.addEventListener('change', event => {
Editor.log(event.detail.value)
});
这个可以了
有直接 拿value的做法吗? 就是点击按钮的时候,我才去取这个值
this.$input_test.value 这样应该就可以了,不行的话,调试一下,看看 this.$input_test 这个里面有什么属性
好的 谢谢
ui-kit文档确实写得太简单了,即没说明主要作用,也没说入口在哪,更没有例子源码,看完依旧束手无策。