SPA,单页应用和(一级路由)脚手架程序的构建

2019-04-17  本文已影响0人  啊肉怪

1场景

1.1后台管理系统

1.1.1、技术栈

1.1.2、IDE

1.2 H5前端开发

1.2.1、技术栈

1.2.2、IDE

1.3 跨端APP开发

1.3.1、技术栈

1.3.2、IDE

后端配置跨域

<dependency>
           <groupId>com.spring4all</groupId>
           <artifactId>swagger-spring-boot-starter</artifactId>
           <version>1.8.0.RELEASE</version>
       </dependency>

WebMvcConfigurer类
package com.springboot.mybatis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
    //跨域配置
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            //重写父类提供的跨域请求处理的接口
            public void addCorsMappings(CorsRegistry registry) {
                //添加映射路径
                registry.addMapping("/**")
                        //放行哪些原始域
                        .allowedOrigins("*")
                        //是否发送Cookie信息
                        .allowCredentials(true)
                        //放行哪些原始域(请求方式)
                        .allowedMethods("GET", "POST", "PUT", "DELETE")
                        //放行哪些原始域(头部信息)
                        .allowedHeaders("*")
                        //暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息)
                        .exposedHeaders("Header1", "Header2");
            }
        };
    }
}

注意:配置文件加注解:@Configuration

@EnableSwagger2Doc

2、一个Vue单页应用(一级路由)脚手架程序的构建

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
    mode:"history",
   routes: [
    {
        //我的班课
      path: '/',
      name: 'Index',
      component: resolve => require(['../components/Index.vue'],resolve)
    },
    {
        //消息
        path:'/task',
        name:'Task',
        component: resolve => require(['../components/Task.vue'],resolve)
    },
    {
        //库管理
        path:'/lib',
        name:'Lib',
        component: resolve => require(['../components/Lib.vue'],resolve)
    },
    {
        //个人中心
        path:'/ucenter',
        name:'UCenter',
        component: resolve => require(['../components/UCenter.vue'],resolve)
    },
    {
        //新建班课
        path:'/new_course',
        name:'NewCourse',
        component: resolve => require(['../components/NewCourse.vue'],resolve)
    },
    {
        //班课详情
        path: '/course/:id',
        name: 'CourseDetail',
        component: resolve => require(['../components/CourseDetail.vue'], resolve)
    }
  ]
})

上一篇下一篇

猜你喜欢

热点阅读