1.Throws ERROR open \settings.txt in windows 7 #39

  1. Open cmd using Admin Privilege
  2. cd c:\users<username>\AppData\Roaming\nvm
  3. copy settings.txt c:\

 

2.[vuex] vuex requires a Promise polyfill in this browser.  在karma

安裝karma-polyfill

在karma.conf.js

module.exports = function(config) {
  config.set({
    frameworks: ['polyfill'],
    polyfill: ['Promise', 'fetch'] // etc. 
    // additional settings here ... 
  });
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()
 
}
}
9.用l5-repository

Target [App\Repositories\ProductRepository] is not instantiable while building [App\Http\Controllers\ProductController].

沒有實例化

要用容器注入到AppServiceProdvide

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()
 
這樣就不用再?token=了

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用法
  1. var bob = simpleCart.add({name: "bob" , price: 2 , color:'blue' , size: 6 }),
  2. joe = simpleCart.add({name: "joe" , price: 3 , color:'orange' , size: 3 }),
  3. jeff = simpleCart.add({name: "jeff" , price: 4 , color:'blue' , size: 4 }),
  4. bill = simpleCart.add({name: "bill" , price: 5 , color:'red' , size: 5 });
  5.         
  6. console.log( simpleCart.find({ color: 'orange' }) ); // [ joe ]
  7. console.log( simpleCart.find({ price: '>=4' }) ); // [ jeff , bill ]
  8. console.log( simpleCart.find({ size: '<5' }) ); // [ bob , joe , jeff ]
  9. console.log( simpleCart.find({ name: "bob" }) ); // [ bob ]
  10. console.log( simpleCart.find({ color: 'blue', size: '<4' }) ); // [ bob ]
 
arrow
arrow
    全站熱搜

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