您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍laravel如何结合vue添加权限,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
使用vue
进行界面管理,实现添加功能
我们在这个目录下存入vue.js
:
resources/admin/node/create.blade.php
:
<!--_meta 作为公共模版分离出去--> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name="renderer" content="webkit|ie-comp|ie-stand"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> <link rel="Bookmark" href="/favicon.ico"> <link rel="Shortcut Icon" href="/favicon.ico" /> <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.min.css" /> <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" /> <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css" /> <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" /> <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" /> <title>添加节点</title> </head> <body> <nav class="breadcrumb"><i class="Hui-iconfont"></i> 首页 <span class="c-gray en">></span> 用户中心 <span class="c-gray en">></span> 添加节点 <a class="btn btn-success radius r" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont"></i></a></nav> <article class="page-container"> <!-- 表单验证 --> @include('admin.common.validate') <form action="{{route('admin.node.store')}}" method="post" class="form form-horizontal" @submit.prevent="dopost"> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否顶级:</label> <div class="formControls col-xs-8 col-sm-9"> <span class="select-box"> <select name="pid" class="select" @change="changePid"> <option :value="info.pid">顶级</option> @foreach($data as $item) <option value="{{$item -> id}}">{{$item -> name}}</option> @endforeach </select> </span> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>节点名称:</label> <div class="formControls col-xs-8 col-sm-9"> <input type="text" v-model.lazy="info.name" class="input-text" placeholder="节点名称" name="name"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3">路由别名:</label> <div class="formControls col-xs-8 col-sm-9"> <input class="input-text" v-model.lazy="info.route_name" placeholder="路由别名" name="route_name"> </div> </div> <div class="row cl"> <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否菜单:</label> <div class="formControls col-xs-8 col-sm-9 skin-minimal"> <div class="radio-box"> <input type="radio" v-model="info.is_menu" value="1"> <label for="sex-1">是</label> </div> <div class="radio-box"> <input type="radio" v-model="info.is_menu" value="0"> <label for="sex-2">否</label> </div> </div> </div> <div class="row cl"> <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3"> <input class="btn btn-primary radius" type="submit" value="添加节点"> </div> </div> </form> </article> <!--_footer 作为公共模版分离出去--> <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script> <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script> <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去--> <!--请在下方写此页面业务相关的脚本--> <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script> <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script> <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script> <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script> <!-- vue --> <script src="/js/vue.js"></script> <script type="text/javascript"> new Vue({ el: '.page-container', data: { info: { _token: "{{csrf_token()}}", pid: 0, name: '', route_name: '', is_menu: 0, } }, methods: { // dopost (e) { // let url = e.target.action // $.post(url, this.info).then((res) => { // console.log(res); // }) // } async dopost (e) { let url = e.target.action let res = await $.post(url, this.info) if (res.status == 1) { location.href ="{{route('admin.node.index')}}" } else { layer.msg(res.msg,{icon: 2, time:1000}); } }, changePid (e) { let pid = e.target.value || 0; this.info.pid = pid; } }, mounted() { } }) </script> </body> </html>
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // 异常处理 try { // 后台验证 $this -> validate($request, [ 'name' => 'required|unique:roles,name' ]); } catch (Exception $e) { return ['status' => 20002, 'msg' => '验证不通过!']; } // 入库 Node::create($request -> except('_token')); return ['status' => 1, 'msg' => '添加节点成功!']; }
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Node extends Base { // 模型中定义修改器 设置route_name 可以为null 方法名set+字段名驼峰式 public function setRouteNameAttribute($value) { // 如果字段值为null,则设置为空字符串,修改和添加时生效 store 或 update $this->attributes['route_name'] = empty($value) ? '' : $value; } }
以上是“laravel如何结合vue添加权限”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。