Как передать объект вместо строки в Nativescript- vue с машинописью? - PullRequest
0 голосов
/ 16 марта 2020

Я хочу реализовать PromptDialog как в {N} Playground Code

import dialogs from "tns-core-modules/ui/dialogs";

  export default {
    methods: {
            onButtonTap() {
                console.log("Button was pressed");
                prompt({
                    title: "Email Prompt",
                    message: "Provide your email address:",
                    okButtonText: "OK",
                    cancelButtonText: "Cancel",
                    defaultText: "name@domain.com",
                    inputType: dialogs.inputType.email
                }).then(result => {
                    console.log(`Dialog result: ${result.result},
                text: ${result.text}`);
                });
            }
        },
  }

Но Vetur выдает следующую ошибку Typescript.

Argument of type '{ title: string; message: string; okButtonText: string; cancelButtonText: string; defaultText: string; inputType: string; }' is not assignable to parameter of type 'string'.

Это просто пример кода в nativescript- vue документация подсказки , но адаптация машинописи.

Basi c использование

    forgotPassword() {
      prompt('Your message to the user', 'Suggested user input').then(result => {
        console.log(`Dialog result: ${result.result}, text: ${result.text}`);
      });
    }

Ошибка Vetur:

Property 'then' does not exist on type 'string'.

1 Ответ

1 голос
/ 16 марта 2020

Это был мисс ведущий документации. Нет API под названием prompt . Это должно быть dialogs.prompt . Правильный пример

<script lang="ts">
    import * as dialogs from "tns-core-modules/ui/dialogs";
     export default {
        methods: {
            onButtonTap() {
                console.log("Button was pressed");
                dialogs.prompt({
                    title: "Email Prompt",
                    message: "Provide your email address:",
                    okButtonText: "OK",
                    cancelButtonText: "Cancel",
                    defaultText: "name@domain.com",
                    inputType: dialogs.inputType.email
                }).then(result => {
                    console.log(`Dialog result: ${result.result},
                text: ${result.text}`);
                });
            }
        },

        data() {
            return {};
        }
    };
</script>
...