LoginSignup
2
2

More than 3 years have passed since last update.

vue.js redis 足跡機能を作ろうぜ

Last updated at Posted at 2019-12-23

足跡機能を作りたい。

参考
https://qiita.com/maip0902/items/eafc35ed762648ddadbf

基礎知識。
来訪ユーザーが重複した場合には、削除され、新しく追加される。
よって、重複して登録されることは無い。

Okwscontroller.php

use Illuminate\Support\Facades\Redis;//忘れずに。

public static function getAshiato(request $request)
{
    $res = Redis::zrevrange('ashiato:'.$request->home_user_id,0,-1);//全員分の足跡をタイムスタンプが新しい順に取得
    return response()->json(['res'=> $res]);
}

public static function addAshiato(request $request)
{
    $res = true;
    Redis::zadd('ashiato:'.$request->home_user_id, time(),$request->user_id);//どのユーザーのページに、いつ訪問したか、来訪したユーザーを追加
    return response()->json(['res'=> $res]);
}


Ashiato.vue


created() {

    this.addAshiato();
    this.getAshiato();

},


methods: {


//足跡を追加(例えばユーザーページに入れる)
addAshiato(){

    let dataform = new FormData();

    dataform.append('home_user_id',100);
    dataform.append('user_id',333);

    axios.post('/okws/addAshiato/', dataform).then(e => {
        console.log(e.data.res);
        console.log("登録成功");
    }).catch((error) => {
        console.log("エラー");
    });

},

//足跡を読み込み
getAshiato(){

    let dataform = new FormData();
    dataform.append('home_user_id',100);
    axios.post('/okws/getAshiato/', dataform).then(e => {
        console.log(e.data.res);
        console.log("取得成功");
    }).catch((error) => {
        console.log("エラー");
    });

}



}


2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2