close
1.Throws ERROR open \settings.txt in windows 7 #39
- Open cmd using Admin Privilege
- cd c:\users<username>\AppData\Roaming\nvm
copy settings.txt c:\
2.[vuex] vuex requires a Promise polyfill in this browser. 在karma
安裝karma-polyfill
在karma.conf.js
module {
config
;
2.mocha chai
http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html
};
3.
import axios Cannot read property ‘protocol’ of undefined
must be
Vue.use(vueaxios,axios) 順序
4.
baseURL
URL要大寫
Vue.axios.defaults.baseURL="http://localhost/laravel/ProductSale/public/api/register"
5.JWTAuth 取得現在的user
$user=Auth::user();
6.
vue plugin install
const Auth={}
Auth.install=function (Vue, options) {
Vue.prototype.$auth=Vue.auth= {
setAuth(token,user){
this.setToken(token)
this.setUser(user)
},
setToken(token){
localStorage.setItem('token',token)
},
setUser(user){
localStorage.setItem('user',JSON.stringify(user))
},
getToken(){
return localStorage.getItem('token')
},
getUser(){
return JSON.parse(localStorage.getItem('user'))
},
isAuthenticate(){
if(this.getToken()){
return true
}else{
return false
}
},
destroyLogin(){
localStorage.removeItem('token')
localStorage.removeItem('user')
}
}
}
export default Auth
7.
存入localstorage要json.stringify parse
8.刷新navbar
data(){
return{
isAuth: this.$auth.isAuthenticate()
}
},
watch:{
'$route':function(){
this.isAuth=this.$auth.isAuthenticate()
}
}
RepositoryServiceProvider下
App::bind('{YOUR_NAMESPACE}Repositories\PostRepository', '{YOUR_NAMESPACE}Repositories\PostRepositoryEloquent');
And use
public function __construct({YOUR_NAMESPACE}Repositories\PostRepository $repository){
$this->repository = $repository;
}
php artisan make:bindings Cats
AppserviceProvider
$this->app->register(RepositoryServiceProvider::class);
10.
JWTAuth取得用戶的方法
$user = JWTAuth::parseToken()->authenticate();
11.
jwt vue laravel
Vue.axios.defaults.headers.common['Authorization']='Bearer '+Vue.auth.getToken()
12.登出
JWTAuth::invalidate($token);
13.
vue產生像google的 pagination
<li :class="{'active':start==page}" v-for="start in pages" class="page-item" >
<a href="#" @click.prevent="changePage(start)"> {{start}}</a>
</li>
---
data
page:1,
page_start:1,
page_end:10,
}
},
computed:{
pages(){
let arrayp=new Array()
for(let i=this.page_start;i<=this.page_end;i++){
arrayp.push(i)
}
return arrayp
}
}
--
methods:{
changePage(n){
this.page=n
this.$emit('fetchProducts',n)
if(n>5){
this.page_start=n-4
if(n+5>this.last_page){
this.page_end=this.last_page
}else{
this.page_end=n+5
}
}else{
this.page_start=1,
this.page_end=10
}
},
14.for迴圈一訂要加let 或var 不然會出錯
15.
swal用法
this.$swal({
title: "確定要刪除?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes,刪了它吧!",
cancelButtonText: "No, 我按錯了!",
}).then(function(){that.$swal('刪了')},(dismiss)=>{if(dismiss==='cancel'){
that.$swal('shit')
}});
16.array find用法
- var bob = simpleCart.add({name: "bob" , price: 2 , color:'blue' , size: 6 }),
- joe = simpleCart.add({name: "joe" , price: 3 , color:'orange' , size: 3 }),
- jeff = simpleCart.add({name: "jeff" , price: 4 , color:'blue' , size: 4 }),
- bill = simpleCart.add({name: "bill" , price: 5 , color:'red' , size: 5 });
- console.log( simpleCart.find({ color: 'orange' }) ); // [ joe ]
- console.log( simpleCart.find({ price: '>=4' }) ); // [ jeff , bill ]
- console.log( simpleCart.find({ size: '<5' }) ); // [ bob , joe , jeff ]
- console.log( simpleCart.find({ name: "bob" }) ); // [ bob ]
- console.log( simpleCart.find({ color: 'blue', size: '<4' }) ); // [ bob ]
全站熱搜