Blogger Information
Blog 28
fans 0
comment 0
visits 65164
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
element ui级联选择器--懒加载数据
蒸蒸
Original
968 people have browsed it

一、vue模板

  1. <el-cascader :props="destiOptionsr" clearable placeholder="请选择目的地2" v-model="value"></el-cascader>

二、JAVASCRIPT代码,加载数据源

  1. export default {
  2. name: "Truckprice",
  3. data() {
  4. return {
  5. destiOptionsr:{
  6. //懒加载的方式加载数据源
  7. lazy:true,
  8. //this.getData定义加载数据源的方法
  9. lazyLoad: this.getData,
  10. },
  11. },
  12. methods:{
  13. getData(node,resolve){
  14. //node是当前点击的节点
  15. const { data } = node;
  16. //获取当前被点击的节点的value
  17. const val=node.value;
  18. //如果没有子节点,回调函数resolve返回空
  19. if (data && ((data.haschild === false) || (data.leaf === true))) {
  20. return resolve([]);
  21. }
  22. let zone = {
  23. zone: val,
  24. };
  25. //被点击的节点的value传输到后端,一共两级,如果value为空,说明请求的是第一级的数据,如果value不为空,说明请求的是第二级的数据
  26. this.$axios.post(this.$host + 'api/gettrucknetwork',zone).then(res => {
  27. resolve(res.data);
  28. })
  29. },
  30. }
  31. }

三、tp5提供后端数据

  1. //获取拖车网点,element ui懒加载
  2. public function gettrucknetwork(Request $request){
  3. //获取前端传递过来的参数zone
  4. $zone=$request->param('zone');
  5. $data=[];
  6. //如果zone为空,则在数据表FivLcltruckPrice中搜索zone,作为第一级数据返回
  7. if($zone==''||$zone==null){
  8. $zone=FivLcltruckPrice::distinct(true)->field('zone')->select();
  9. foreach($zone as $key=>$value){
  10. $data[$key]['value']=$value->zone;
  11. $data[$key]['label']=$value->zone;
  12. //一共两级,这是第一级,所以不是叶子节点leaf=false
  13. $data[$key]['leaf']=false;
  14. }
  15. }else{
  16. //如果zone不为空,则在数据表FivLcltruckPrice中搜索address,作为第二级数据返回
  17. $address=FivLcltruckPrice::where('zone',$zone)->field('address')->select();
  18. foreach($address as $key=>$value){
  19. $data[$key]['value']=$value->address;
  20. $data[$key]['label']=$value->address;
  21. //一共两级,这是第二级,所以是叶子节点leaf=true
  22. $data[$key]['leaf']=true;
  23. }
  24. }
  25. //数据以json格式返回到前端
  26. return json($data);
  27. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post