当前位置: 首页 > 后端技术 > Node.js

SpringBoot【Vue+VueCLI3+Vant快速搭建你的手机商城】

时间:2023-04-03 20:37:49 Node.js

攻略记录是在原有后台API的基础上搭建手机商城,并参考已有的Android应用UI设计图进行开发。技术选择后端SpringCloudOAuth2+SpringCloudEureka+SpringBoot前端Vue+VueRouter+VueCLI3+Vant;手机商城从技术选型到项目上线需要一周时间,后期优化测试需要3天时间,团队规模2人14人天的后台api是基于原来的androidapi,后来增加了一些没有的接口。工作分为页面开发3天,对接联调测试4天。大法好哈哈,开始思考部署静态页面到阿里云oss并配置我们自己的域名;静态页面通过OAuth2密码方式登录获取Token,携带Token请求api网关,因为存在跨域问题部署在不同域名下需要在后台显示的语句比如api中的ResourceServer需要加上.cors()@Configuration@EnableResourceServerpublicclassResourceServerConfigextendsResourceServerConfigurerAdapter{/***省略其他**/@Overridepublicvoidconfigure(HttpSecurityhttp)throwsException{http.authorizeRequests().antMatchers("/user/**","/upload","/version").permitAll().and().cors()//.and().csrf().disable().exceptionHandling().authenticationEntryPoint((request,response,authException)->response.sendError(HttpServletResponse.SC_UNAUTHORIZED)).and().authorizeRequests().anyRequest().authenticated().and().httpBasic();}}@ConfigurationpublicclassMvcConfigextendsWebMvcConfigurerAdapter{@OverridepublicvoidaddCorsMappings(CorsRegistryregistry)inMvcConfig.addMapping("/**").allowedOrigins("http://m.xx.com","http://localhost:8080").allowedMethods("*").allowedHeaders("*").allowCredentials(true).maxAge(3600);}}页面效果优化还在进行中。使用PWA对其进行改造。目前仅支持谷歌浏览器、百度浏览器和新版safari,以获得接近原生应用的体验。可以在启动后期添加主屏添加缓存,提升用户体验,减轻后端压力。参考vant文档VueCLI3