【发布时间】:2018-05-31 21:35:55
【问题描述】:
我想将 props 从父组件传递给子组件。我的道具是tid。
这是父组件:
<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。
如何在 mount 或 created 钩子中获取 tid?
【问题讨论】:
-
对我来说一切正常。
track.category_id是否在您的父级中定义?
标签: javascript laravel vuejs2 axios