duo

6018 经验值

生成小程序码、微信扫小程序码登录web端,后面能讲下吧?

这些基础知识是为了小程序吗?

分页

// 返回Array
$user = User::findOrFail($id);
return $this->response->array($user->toArray());

// 返回 Single Item
$user = User::findOrFail($id);
return $this->response->item($user, new UserTransformer);

// 返回 A Collection Of Items
$users = User::all();
return $this->response->collection($users, new UserTransformer);

// 返回 Paginated Items
// 说明:分页结构在 body 里的meta元素里
$users = User::paginate(25);
return $this->response->paginator($users, new UserTransformer);

// 返回 No Content
return $this->response->noContent();


// 返回 Created Response
// 说明:可以用在返回token的时候,内容塞在 header里
return $this->response->created();

Mac全局配置文件
touch ~/.eslintrc.json
用sublime编辑json文件
subl ~/.eslintrc.json
使用airbnb规范
安装airbnbjavascript/packages/eslint-config-airbnb-base at master · airbnb/javascript · GitHub

{
    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true
    },
    "extends": "airbnb",
    "plugins": ["html","markdown"],
    "rules": {
        "no-console":0
    }
}

Notes
Ajax 返回的顺序不确定

<head>
    <title>Promise Intro</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        let user;

        $.get('https://api.github.com/users',data=>{
            console.log('fetched all users');
            user = data[0].login;
        });

        $.get(`https://api.github.com/users/${user}/repos`,data => {
            console.log('fetched user repos');
            console.log(data);
        })
    </script>
</body>

嵌套写法,写在第一个请求的回调函数里,嵌套越多越混乱,会坠入回调地狱。

<script type="text/javascript">
        let user;

        $.get('https://api.github.com/users',data=>{
            console.log('fetched all users');
            user = data[0].login;

            $.get(`https://api.github.com/users/${user}/repos`,data => {
            console.log('fetched user repos');
            console.log(data);
        })
        });
        
    </script>

为解决回调不确定性和回调地狱,ES6提供了Promise承诺,比如:订单号。
用axios包来做下
.then()//事件监听成功之后执行 .catch()//返回错误信息

<head>
    <title>Promise Intro</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.17.1/axios.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        const usersPromise = axios.get('https://api.github.com/user');

        //$('p').on('click',function(){})  用.then()方法
        usersPromise
        .then(reponse =>{
            username =reponse.data[0].login;
            return axios.get(`https://api.github.com/users/${username}/repos`);
        })
        .then(reponse =>{
            console.log(reponse.data);
        })
        .catch(err =>{
            console.log(err);
        })
    </script>
</body>

笔记

<title>Spread Operator Intro</title>
    <style type="text/css">
    body{
        background-color: #ffa500;
        text-align: center;
        justify-content: center;
        align-items: center;
        font-family: sans-serif;
        font-size: 50px;
        color:white;
        text-shadow: 3px 3px 0 rgba(0,0,0,0.2);
    }
    .heading span{
        cursor:pointer;
        display:inline-block;
        transition: transform 0.25s;
    }
    .heading span:hover{
        transform: translateY(-20px) rotate(10deg) scale(2);
    }
    </style>
</head>
<body>
    <h2 class="heading">VEGETABLE</h2>
    <script type="text/javascript">
        const heading = document.querySelector('.heading');
        heading.innerHTML = wrapWithSpan(heading.textContent);

        function wrapWithSpan(word){
            return [...word].map(letter => `<span>${letter}</span>`).join('');
        }
    </script>
</body>

笔记:

<script type="text/javascript">
        const id = '15212619000504093X';
        const fan = 'I love vegetables.';
        const heading = `${'='.repeat(5)} ${fan} ${'='.repeat(5)}`;

        console.log(heading);//美化字符串

        //.startsWith()
        //id.startsWith('15')
        //id.startsWith('1900',6)
        //大小写敏感fan.startsWith('I')

        //.endsWith()
        //id.endsWith('X')
        //fan.endsWith('love',6)

        //.includes()
        //以前的用法fan.indexOf('vegetables')!= -1
        //fan.includes('vegetables')
        //fan.includes('veg',10)

        //.repeat()重复
        //'ha'.repeat(5)
    </script>