質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Q&A

0回答

1003閲覧

Vue.js Composition API Watch 配列の指定について

104m

総合スコア1

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

0グッド

0クリップ

投稿2020/10/04 03:46

わからない点

watchで配列データを監視対象とする方法を教えてください。
従来では配列データでsample.aを指定する場合、
クォーテーションで囲めば扱えましたが、
Composition APIだとエラーとなります。

### ソース

js

1<script lang="ts"> 2import Vue from "vue"; 3import { defineComponent, reactive, watch } from "@vue/composition-api"; 4 5export default defineComponent({ 6 name: "sampleVue", 7 setup() { 8 const sample = reactive({ 9 a: "a" 10 }) 11 watch(sample.a,() => { 12 alert("watched") 13 }) 14 }, 15}); 16</script>

エラー

No overload matches this call. Overload 1 of 3, '(sources: readonly WatchSource<unknown>[], cb: WatchCallback<readonly unknown[], readonly unknown[]>, options?: WatchOptions<false>): WatchStopHandle', gave the following error. Argument of type '"sample.a"' is not assignable to parameter of type 'readonly WatchSource<unknown>[]'. Overload 2 of 3, '(source: WatchSource<unknown>, cb: WatchCallback<unknown, unknown>, options?: WatchOptions<false>): WatchStopHandle', gave the following error. Argument of type '"sample.a"' is not assignable to parameter of type 'WatchSource<unknown>'. Overload 3 of 3, '(source: object, cb: WatchCallback<object, object>, options?: WatchOptions<false>): WatchStopHandle', gave the following error. Argument of type '"sample.a"' is not assignable to parameter of type 'object'.Vetur(2769)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問