ElementUI中如如何实现表单验证、数据绑定、路由跳转
这篇文章主要介绍ElementUI中如如何实现表单验证、数据绑定、路由跳转,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
成都创新互联是专业的呈贡网站建设公司,呈贡接单;提供成都网站建设、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行呈贡网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
1.新建表单组件el-form.vue
提交
2.新建一个Module,EleUserInfo.js
import Vue from "vue"; import {routerConfig} from "./../../jssrc/config"; export default{ state:{ UserForm:{truename:"", age:"", birthday:""}, CheckRules:{ truename:[ {required:true, message:"请输入活动名称", trigger:'blur'}, {min:3, max:5, message:"必须3-5个字符", trigger:'blur'} ], age:[{validator:(rule,value,callback)=>{ if(/^\d+$/.test(value) == false){ callback(new Error("年龄只能输入数字")); }else{ callback(); } }, trigger:'blur'}] }, }, actions:{ setUserInfo(context){ // 路由跳转 routerConfig.push({name:"newslist"}); } } }
3.我们把jssrc/index.js 中的代码分离出一部分
config.js
import VueRouter from 'vue-router'; import newsdetail from "./../components/news-detail.vue"; import eltable from "./../components/el-table.vue"; import elindex from "./../components/elmentui/el-index.vue"; import elhot from "./../components/elmentui/el-hot.vue"; import eluserinfo from "./../components/elmentui/el-form.vue"; const userlogin = resolve => { // 成功之后的回调 resolve(require("./../components/user-login.vue")); // 这就是异步加载的方式 } const newslist = resolve => { // 成功之后的回调 resolve(require("./../components/news-list.vue")); // 这就是异步加载的方式 } // 路由模块 export const routerConfig = new VueRouter({ routes: [ { path: '/', component: userlogin}, { path: '/news', component: newslist, name:"newslist"}, { path: '/news/:newsid', component: newsdetail, name:"newsdetail"}, { path: '/login', component: userlogin,name:"userlogin" }, { path: '/eltable', component: eltable,name:"eltable" }, { path: '/elindex', component: elindex,name:"elindex", children:[ {path:"hot",component:elhot,name:"elhot"}, {path:"userinfo",component:eluserinfo,name:"eluserinfo"}, ]} ] })
4.然后jssrc/index.js 修改成如下
import Vue from "vue"; import pagenav from "./../components/page-nav.vue"; // 引入 import validate from "./../components/validate"; // 使用 Vue.use(validate); import VueRouter from 'vue-router'; Vue.use(VueRouter); // 全局使用插件 import VueResource from 'vue-resource'; Vue.use(VueResource); import UserModule from "./../store/modules/UserModule"; import NewsModule from "./../store/modules/NewsModule"; import EleModule from "./../store/modules/eleModule"; import EleUserInfomoldule from "./../store/modules/EleUserInfo"; import Vuex from 'vuex'; Vue.use(Vuex); import ElementUI from 'element-ui'; import 'element-ui/lib/theme-default/index.css'; Vue.use(ElementUI); const vuex_store = new Vuex.Store({ modules:{ users:UserModule, news:NewsModule, ele:EleModule, userinfo:EleUserInfomoldule } }) //路由的配置 import {routerConfig} from "./config"; // 全局组件,不加入路由管理 Vue.component("page-nav",pagenav); let myvue = new Vue({ el:".container", store:vuex_store, //注入到vue router:routerConfig, });
5.查看效果
以上是“ElementUI中如如何实现表单验证、数据绑定、路由跳转”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
新闻标题:ElementUI中如如何实现表单验证、数据绑定、路由跳转
当前URL:http://ybzwz.com/article/joepch.html