前提・実現したいこと
いつもお世話になっております。
Vue.js でAWSのAPI GatewayにデータをPostをしようとしています。
Postする際に送信するデータの内容をクオーテーションで囲んで宣言していたときは
Requestは成功しておりました。
axios.post("#####URL######", { hoge: 'qwertyuyuioghj' }
しかし、送信するデータをVuexのGettersから取得した変数(hoge)をthis.hogeと宣言し、Postをすると
Status 400のエラーになってしまいます。
axios.post("#####URL######", { hoge: this.hoge }
VuexのGettersで取得した変数をPostしたいときはどのように、変数を宣言すれば良いのでしょうか。
発生している問題・エラーメッセージ
Error: Request failed with status code 400
at createError (createError.js?16d0:16)
at settle (settle.js?db52:17)
at XMLHttpRequest.handleLoad (xhr.js?ec6c:59)
該当のソースコード
vue.js
<script> import axios from 'axios'; export default { data() { return { hoge: "" } }, computed: { hoge() { return this.$store.getters.hoge }, }, watch: { piyo: function(v) { if (v.length >= 4) { axios.post("#####URL######", { hoge: this.hoge //<=this.hogeを'qwertyuyuioghj'のように指定していた }, { headers: { 'Content-Type': 'application/json', 'x-api-key': process.env.API_KEY } }) .then(response => { console.log(response.data.test) }) .catch(function(error) { console.log(error) }); } }, }, } </script>試したこと
postする際に送信するデータの記述方法を色々試しました。
試した変数の宣言方法
hoge
this.hoge
$store.getters.hoge
this.$store.getters.hoge
あなたの回答
tips
プレビュー