我想將道具從父組件傳遞給子組件。我的道具是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;
我想通過tid
值爲http.get
函數。例如:
Http.get('/api/interactive/lib/' + this.tid)
然而tid
值爲undefined
。 如何在掛載或創建的掛鉤中獲得tid
?
一切看起來我的權利。您的父級中定義了「track.category_id」嗎? –