親コンポーネントから子コンポーネントに小道具を渡したいと思います。私の小道具はtid
です。Axiosの小道具をVue.jsに渡しますか?
これは、親コンポーネントである:これは、子コンポーネントである
<div id="tracksec" class="panel-collapse collapse">
<library :tid="track.category_id"></library>
</div>
:
<script>
import Chapter from "./chapter";
import Http from "../../services/http/httpService";
export default {
components: {Chapter},
props:['tid'],
name: "library",
data(){
return{
library:{},
}
},
computed:{
getPr(){
return this.$props;
}
},
mounted(){
console.log(this.$props);
Http.get('/api/interactive/lib/' + this.tid)
.then(response => this.library = response.data)
.catch(error => console.log(error.response.data))
}
}
これは、httpソースです:
import axios from 'axios';
class httpService {
static get(url, params) {
if (!params) {
return axios.get(url);
}
return axios.get(url, {
params: params
});
}
static post(url, params) {
return axios.post(url, params);
}
}
export default httpService;
私がしたいです0123を渡すの値はhttp.get
関数になります。例えば:
Http.get('/api/interactive/lib/' + this.tid)
tid
値がundefined
あるが。 マウントされたフックまたは作成されたフックでtid
を取得するにはどうすればよいですか?親コンポーネントで
すべてが右の私には見えます。あなたの親に 'track.category_id'が定義されていますか? –