1.header 用

headers x-requested-with    XMLHttpRequest

告知後端代表發送的是ajax

2.jwt laravel

2.1

登入

$token=JWTAuth::attempt($credential)

2.2

用exception

      if($exception instanceof TokenExpiredException){
            return Response::json(['error'=>'Token Expired'],$exception->getStatusCode());

        }else if($exception instanceof TokenInvalidException){
            return Response::json(['error'=>'Token invalid'],$exception->getStatusCode());

        }else if($exception instanceof JWTException){
            return Response::json(['error'=>'faild fetcch token'],$exception->getStatusCode());
2.3

route用Middleware看是否有正確token

        'auth.jwt'=>\Tymon\JWTAuth\Middleware\GetUserFromToken::class
2.4

取user的data

       $user=JWTAuth::parseToken()->toUser();
3.

jwt

https://yami.io/jwt/

4.Vue plugin 用法

var MyPlugin = {}; MyPlugin.install = function(Vue, options){ var service = { getName(){ retrun this.name; }, getNameVersion2(vm){ return vm.name; } } Vue.prototype.$service = service; };

var Auth={};
Auth.install=function(Vue,options){
var auth={
getToken(){
return localStorage.getItem('token');
}
}
Vue.prototype.$auth=auth;
}
export default Auth;
5.Object.defineProperties 和Object.defineProperty
5.1
var obj = {};
Object.defineProperties(obj, {
  'property1': {
    value: true,
    writable: true
  },
  'property2': {
    value: 'Hello',
    writable: false
  }
  // etc. etc.
});

5.2

a={};
Object.defineProperties(a,{
  'shit':{
    value:'sa',
    writeable:true
  },
  'gg':{
    value:'as'
  }
});

6.slice

a=['a','b','c'];

只有一個參數時

a.slice(1) 指定位置到最後一個位置 b,c

a.slice(-2) b,c

兩個參

a.slice(0,2) a,b

a.slice(-3,-1) a,b

arrow
arrow
    全站熱搜

    學習程式 發表在 痞客邦 留言(0) 人氣()