如何将打字稿代码实现到vue组件中?

时间:2019-11-15 16:02:10

标签: typescript vue.js nativescript-vue

https://github.com/bradmartin/nativescript-texttospeech

texttospeech具有用TS编写的文档。

如何将代码转换为ns-VUE?

jq

我不想使用打字稿,我所需要的只是一个可以在Nativescript-Vue中使用的按钮。

预先感谢

2 个答案:

答案 0 :(得分:1)

只需从speakOptions中删除类型并将其从导入中删除:

import { TNSTextToSpeech } from 'nativescript-texttospeech';

let TTS = new TNSTextToSpeech();

let speakOptions = {
  text: 'hello world',
};

TTS.speak(speakOptions); 

答案 1 :(得分:0)

如果其他人试图将TS转换为原始JS,请尝试TypeScript Playground

这就是我想要做的。


<template>
  <Page>
    <ActionBar title="Welcome" />
    <StackLayout>
      <Label class="message" :text="speakOptions.text" col="0" row="0" />
      <Button text="talk" @tap="talk('welcome')" />
    </StackLayout>
  </Page>
</template>

<script >
import { TNSTextToSpeech } from "nativescript-texttospeech";

let TTS = new TNSTextToSpeech();

export default {
  data() {
    return {
      speakOptions: {
        text: "hello"
      }
    };
  },
  methods: {
    talk: function(message) {
      this.speakOptions.text = message;
      TTS.speak(this.speakOptions);
    }
  }
};
</script>

<style scoped>
</style>