相关疑难解决方法(0)

在Vuejs 2.0中使用“ this”

我是VueJS的新手。我有一个小问题,我无法弄清楚。希望有人能给我提示。

我正在创建一个语音搜索按钮,基本上,当我单击语音按钮时,它将记录我的语音并以表格形式将其打印到输入属性中。

<input type="text" name="inputSearch" id="inputSearch"
v-model="inputSearch" class="form-control" x-webkit-speech>
Run Code Online (Sandbox Code Playgroud)

这是我在VueJS中的脚本

<script>
export default {
        data() {
          return {
                    inputSearch: '',
                    show: false
                 }
        },
        methods: {
          voiceSearch: function(event){
                    this.inputSearch = '';
                    this.show = false;
                    if (window.hasOwnProperty('webkitSpeechRecognition')) {
                    var recognition             = new webkitSpeechRecognition();
                    recognition.continuous      = false;
                    recognition.interimResults  = false;
                    recognition.lang            = "en-US";
                    recognition.start();
                    recognition.onresult = function(e) {
                    this.inputSearch = e.results[0][0].transcript;
                     recognition.stop();
                        };
                    recognition.onerror = function(e) {
                          alert('There are something wrong...');
                          recognition.stop();
                    };



                    }else {
                      alert('Your browser does not support HTML5/WebKitSpeech. You …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2

2
推荐指数
1
解决办法
918
查看次数

标签 统计

javascript ×1

vue-component ×1

vue.js ×1

vuejs2 ×1