查询接口,vue前端

查询和获取数据库所有数据写在一起

//审核后台得到视频列表
    public function getVideoList()
    {
        $input = $this->getinput->json();
        if (isset($input['page'])) {
            $offset = ($input['page'] - 1) * 10;
            $limit = 10;
        } else {
            $offset = 0;
            $limit = 100;
        }
//        总条件
        $query = $this->db;

//如果需要查询某一项 加上查询语句
        if (isset($input['film_name'])) {
            $query = $query->where('film_name', $input['film_name']);
        }
//        查询后得到总结果
        $count_query = clone $query;
        $result_query = clone $query;
//        得到总结果的条数
        $count = $count_query->get('video')->num_rows();
//        根据查询结果得到这个条数
        $result = $result_query->order_by('created_at', 'desc')->offset($offset)->limit($limit)->get('video')->result_array();
        $data = array(
            'data' => $result,
            'total' => $count,
        );
        echo json_encode($data);
    }

vue内容

get_VideoList: async function () {
                let self = this;
                //搜索条件,电影名称
                if(this.film_name===''){
                    this.film_name=undefined
                }
                this.params={
                    page: this.currentPage,
                    film_name:this.film_name
                }
                let {data} = await this.$http.post('/getVideoList',this.params)
                console.log(data)
                self.video_list = data.data
                self.total = data.total
                for (var i = 0; i < self.video_list.length; i++) {
                    if (self.video_list[i].states == 0) {
                        self.video_list[i].states = false
                    } else {
                        self.video_list[i].states = true
                    }
                }
            },

你可能感兴趣的:(PHP)