【发布时间】:2019-08-15 10:04:58
【问题描述】:
我正在尝试检索全局会话值并将其设置为 vue 变量。问题是, id 变量没有在控制台上显示任何值,但确实在 vue 组件上显示了值。我已经检查了 vue devtools 并且 id 确实包含正确的值。
Vue 组件
<template>
<div class="container">
<h1>{{id}}</h1> // the id does displays the value
</div>
</template>
<script>
export default {
data () {
return {
id:'',
}
},
created(){
axios.get('api/studentlecture').then(response => this.id = response.data).catch(function(error){console.log(error)
});
console.log(this.id)
},
methods:{
},
mounted() {
console.log('Component mounted.')
}
}
控制器
public function index()
{
$id= session('userID');
return json_encode($id);
}
【问题讨论】:
标签: php laravel vue.js laravel-artisan