我想将道具从父组件传递给子组件。我的道具是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”吗? –