わからない点
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)
あなたの回答
tips
プレビュー