Vue.prototype和sessionStorage的使用简介
1、Vue中的全局变量如何实现?在Vue中多个页面间的变量的保存与读取如何实现?2、Vue中的全局变量是通过 Vue.prototype实现的如我们的客户端数据接口BASE_URLD main.js中定义如下:Vue.prototype.BASE_URLD = 'http://127.0.0.1:8080';在其他页面引用如下:script>
·
1、Vue中的全局变量如何实现?
在Vue中多个页面间的变量的保存与读取如何实现?
2、Vue中的全局变量是通过 Vue.prototype实现的
如我们的客户端数据接口BASE_URLD main.js中定义如下:
Vue.prototype.BASE_URLD = 'http://127.0.0.1:8080';
在其他页面引用如下:
<script>
methods: {
getList(){
this.$http.post(this.BASE_URLD + '/mobile/getList.do',{type:1)
.then(function (res) {
})
.catch(function (error) {
});
}
}
</script>
3、通过sessionStorage实现在Vue中多个页面间的变量的保存与读取
如在登录成功后,我们将用户名保存在sessionStorage中
sessionStorage.setItem('userName', res.data.userName);
在其他页面,我们通过sessionStorage取出用户名
var userName = sessionStorage.getItem('userName');
更多推荐
已为社区贡献4条内容
所有评论(0)