Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 加载页面时,无法将焦点设置为文本区域_Vue.js_Vuejs2_Vue Component_Syncfusion - Fatal编程技术网

Vue.js 加载页面时,无法将焦点设置为文本区域

Vue.js 加载页面时,无法将焦点设置为文本区域,vue.js,vuejs2,vue-component,syncfusion,Vue.js,Vuejs2,Vue Component,Syncfusion,我试图将焦点设置在syncfusion文本区域上,但我无法这样做。当组件按照定义装载时,我使用了this.$nextTick,但系统仍然不关注文本区域。 我在created事件中添加了相同的“focus to textarea”代码,因为created事件是在mounted事件之后触发的。 我重新创造了这个问题。 我还看到this.$refs.vocabularies.$el返回input#vocabularies.e-control.e-textbox.e-lib 我做错了什么 <te

我试图将焦点设置在syncfusion文本区域上,但我无法这样做。当组件按照定义装载时,我使用了this.$nextTick,但系统仍然不关注文本区域。 我在
created
事件中添加了相同的“focus to textarea”代码,因为
created
事件是在
mounted
事件之后触发的。 我重新创造了这个问题。 我还看到
this.$refs.vocabularies.$el
返回
input#vocabularies.e-control.e-textbox.e-lib

我做错了什么

<template>
            <ejs-textbox cssClass="height:500px;" id='vocabularies' :multiline="true" placeholder="Enter your vocabularies" floatLabelType="Auto" :input= "inputHandler" v-model="vocabularies" ref="vocabularies"/>
</template>
<script>
import '@syncfusion/ej2-base/styles/material.css';
import '@syncfusion/ej2-vue-inputs/styles/material.css';    
export default
{
    data() {
        return {
            vocabularies: '',
            inputHandler: (args) => 
            {
                args.event.currentTarget.style.height = "auto";
                args.event.currentTarget.style.height = (args.event.currentTarget.scrollHeight)+"px";
            },
        }
    },
    mounted() 
    {       
        this.$nextTick(function()
        {
            this.$refs.vocabularies.$el.style.height = "auto";
            this.$refs.vocabularies.$el.style.height = (this.$refs.vocabularies.$el.scrollHeight)+"px";
            this.$refs.vocabularies.$el.focus();
        console.log(`mounted run`);
        });
    },
    async created() 
    {
        this.$nextTick(function()
        {
            this.$refs.vocabularies.$el.style.height = "auto";
            this.$refs.vocabularies.$el.style.height = (this.$refs.vocabularies.$el.scrollHeight)+"px";
            this.$refs.vocabularies.$el.focus();
            console.log(`created run`);
        });
    }, 
</script>

导入“@syncfusion/ej2base/styles/material.css”;
导入“@syncfusion/ej2 vue inputs/styles/material.css”;
导出默认值
{
数据(){
返回{
词汇:'',
InPurthandler:(args)=>
{
args.event.currentTarget.style.height=“自动”;
args.event.currentTarget.style.height=(args.event.currentTarget.scrollHeight)+“px”;
},
}
},
安装的()
{       
此.$nextTick(函数()
{
这是。$refs.vocabularies。$el.style.height=“auto”;
this.$refs.vocabularies.$el.style.height=(this.$refs.vocabularies.$el.scrollHeight)+“px”;
这是。$refs.vocabularies。$el.focus();
log(`mountedrun`);
});
},
异步创建()
{
此.$nextTick(函数()
{
这是。$refs.vocabularies。$el.style.height=“auto”;
this.$refs.vocabularies.$el.style.height=(this.$refs.vocabularies.$el.scrollHeight)+“px”;
这是。$refs.vocabularies。$el.focus();
log(`created run`);
});
}, 

所以,我是这样解决的。我不太确定这种方法有多好,因为我没有使用过syncfusion,所以不能说是否有更好的方法

<ejs-textbox cssClass="test" id='vocabularies' :multiline="true" placeholder="Enter your vocabularies" floatLabelType="Auto" :input= "inputHandler" v-model="vocabularies" ref="vocabularies"/>

下面是我如何解决这个问题的。我不太确定这个方法有多好,因为我没有使用过syncfusion,所以不能说是否有更好的方法

<ejs-textbox cssClass="test" id='vocabularies' :multiline="true" placeholder="Enter your vocabularies" floatLabelType="Auto" :input= "inputHandler" v-model="vocabularies" ref="vocabularies"/>

我能够通过在
mounted()
方法中使用
this.$refs.vocabularies.focusIn();
解决问题,基于文档我能够通过在
mounted()中使用
this.$refs.vocabularies.focusIn();
解决问题
方法,根据文档

您可以在创建的事件中使用TextBox组件的focusInpublic方法来聚焦文本区域。请参考以下代码

    <ejs-textbox cssClass="height:500px;" id='vocabularies' :multiline="true" placeholder="Enter your vocabularies" floatLabelType="Auto" :input= "inputHandler" v-model="vocabularies" ref="vocabularies" :created='onCreated' />


     onCreated:function(){
         this.$refs.vocabularies.ej2Instances.focusIn()
     }

onCreated:function(){
这是。$refs.vocabularies.ej2Instances.focusIn()
}
请从下面的链接中查找示例

示例链接:


您可以在创建的事件中使用文本框组件的focusInpublic方法来聚焦文本区域。请参考以下代码

    <ejs-textbox cssClass="height:500px;" id='vocabularies' :multiline="true" placeholder="Enter your vocabularies" floatLabelType="Auto" :input= "inputHandler" v-model="vocabularies" ref="vocabularies" :created='onCreated' />


     onCreated:function(){
         this.$refs.vocabularies.ej2Instances.focusIn()
     }

onCreated:function(){
这是。$refs.vocabularies.ej2Instances.focusIn()
}
请从下面的链接中查找示例

示例链接:


是否可以创建此问题的实时演示?@Himanshu,我尝试在我的应用程序中使用自定义指令,但无效。我还对创建的事件进行了注释,以查看是否有帮助(但没有)。在这种情况下,如果你能分享一些小提琴就更好了。Hello@Himanshu,这里有一个关于这个问题的codesandbox链接:可以创建这个问题的实时演示吗?@Himanshu,我已经尝试在我的应用程序中使用自定义指令,但它不起作用。我还注释掉了创建的事件,看看这是否有帮助(但没有).在这种情况下,如果你能分享一些小提琴就更好了。你好@Himanshu,这里有一个关于这个问题的代码沙盒链接: