weex 的 input 组件中的blur和focus函数无法调用?

新手上路,请多包涵

问题

无法调用weex的input组件中的blur和focus 函数。 但我调用input的blur(focus)函数时,键盘并没有被收起,此时查看Android studio 打印的日志提示一下错误

12-01 16:13:30.791 32201-32214/com.example.zhangshijie.myapplication E/jsengine:  ReportException :undefined:5: TypeError: Object [object Object] has no method 'blur'
12-01 16:13:30.802 32201-32214/com.example.zhangshijie.myapplication E/jsengine:  ReportException : TypeError: Object [object Object] has no method 'blur'
                                                                                     at t.default.methods.click (eval at Jt ((weex):4:2004), <anonymous>:5:632)
                                                                                     at Object.n [as fn] ((weex):3:3068)
                                                                                     at null.<anonymous> ((weex):3:10683)
                                                                                     at L.Object.assign.fireEvent ((weex):2:29647)
                                                                                     at G.Object.assign.fireEvent ((weex):3:886)
                                                                                     at (weex):4:488
                                                                                     at Array.forEach (native)
                                                                                     at Object.Ft [as receiveTasks] ((weex):4:384)
                                                                                     at Object.M.tu.(anonymous function) [as callJS] ((weex):1:8334)
                                                                                     at global.(anonymous function) ((weex):7:1148)
12-01 16:13:30.802 32201-32214/com.example.zhangshijie.myapplication E/weex: reportJSException >>>> instanceId:1, exception function:callJS, exception:TypeError: Object [object Object] has no method 'blur'

下面是我的.vue 文件内容

<template>
  <div @click="click" class="bounds">
      <input ref = "inputMessage" class= "input" type="text" value="测试数据"></input>
  </div>
</template>

<style scoped>

.input {
    top: 100;
    width: 600;
    left: 50;
    height: 100;
    background-color: red
}
.bounds {
    position: absolute;
    top: 0;
    left: 0;
    width: 750;
    background-color: green
}
</style>


<script>
export default {
    methods: {
        click: function(e) {
            this.$refs.inputMessage.blur()
            // console.log('this.refs', this.refs)
        }
    }
}
</script>
阅读 4.3k
1 个回答

试试把ref="inputMessage"改成ref="'inputMessage'"或者通过this.$refs['insputMessage'].blur()去调用

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题