解决跨域:

1、后台 cors cnpm i -S cors

2、前端 jsonp

3、代理 webpack: myvue\config\index.js 找 proxyTable

  1. proxyTable: {
  2. "/anhao": {
  3. target: "http://localhost:3000",
  4. changeOrigin: true,
  5. pathRewrite: {
  6. //需要rewrite重写的, 如果在服务器端做了处理则可以不要这段
  7. "^/anhao": ""
  8. }
  9. }
  10. },
vue插件:

axios vue-axios vue2-animate vuex swiper

cnpm i -S axios vue2-animate vuex swiper

vuex swiper //轮播特效copy


移动端布局:rem

  1. rem: r---> html em
  2. html{font-size:100px;}
  3. 标准的字体大小 100 当前的字体的大小 rem?
  4. ------------------- = -------------------
  5. 表示视图的宽度 750 当前的视图的宽度 document.documentElement.clientWidth
  6. 320px 640px 750px 1250px
  7. rem?= 100/750*clientWidth = clientWidth/(7.5|3.75) + "px";

  1. <transition>
  2. <div v-show="isShow"></div>
  3. </transition>

vue--->vuex

1、直接调用mutations ----> commit

2、直接调用actions ---> dispatch

mai zuo wang:

首页,头部,菜单,banner图

Main.js:
  1. import Vue from "vue";
  2. import VueAxios from "vue-axios";
  3. import Axios from "axios";
  4. import App from "./App";
  5. import store from "./store";
  6. import router from "./router";
  7. import "vue2-animate/dist/vue2-animate";
  8. //Vue.prototype.$http = axios;//引入axios
  9. Vue.use(VueAxios,Axios);//引入axios
  10. Vue.config.productionTip = false;
  11. /* eslint-disable no-new */
  12. new Vue({
  13. el: "#app",
  14. router,
  15. store,
  16. components: { App },
  17. template: "<App/>"
  18. })
store/index.js

vuex的store配置

  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. import Axios from "axios";
  4. Vue.use(Vuex);
  5. let store = new Vuex.Store({
  6. state:{
  7. isShow:false,
  8. title:"",
  9. },
  10. getters:{},
  11. mutations:{
  12. showMutation(state,payload){
  13. state.isShow = !state.isShow;
  14. //console.log("payload",payload);
  15. },
  16. yingyuanMutation(state,payload){
  17. state.title = "全部影院";
  18. },
  19. changeMutation(state,payload){
  20. state.title = "卖座电影";
  21. },
  22. loginMutation(state,payload){
  23. state.title = "登录";
  24. },
  25. },
  26. actions:{
  27. showAction({commit},payload){
  28. commit("showMutation");
  29. },
  30. changeAction({commit},payload){
  31. commit("changeMutation");
  32. },
  33. yingyuanAction({commit},payload){
  34. commit("yingyuanMutation");
  35. },
  36. loginAction({commit},payload){
  37. commit("loginMutation");
  38. },
  39. },
  40. modules:{},
  41. });
  42. console.log(111111,store.state.title)
  43. export default store;
router/index.js

路由配置js

  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import Home from '@/components/Home';
  4. import Login from '@/components/Login';
  5. import City from '@/components/City';
  6. import FilmList from "@/components/FilmList";
  7. import FilmDetail from "@/components/FilmDetail";
  8. import Cinema from "@/components/Cinema";
  9. import Order from "@/components/Order";
  10. Vue.use(Router)
  11. const router = new Router({
  12. routes: [
  13. {path: '/',name: 'home',component: Home},
  14. {path: '/login',name: 'login',component: Login},
  15. {path: '/city',name: 'city',component: City},
  16. {path: "/filmlist",name: "filmlist",component: FilmList},
  17. {path: "/filmdetail/:id",name: "filmdetail",component: FilmDetail,props:true},
  18. {path:"/cinema",name:"cinema",component:Cinema},
  19. {path:"/order",name:"order",component:Order},
  20. {path: "/*",redirect:"/"},
  21. ]
  22. });
  23. router.beforeEach((to, from, next) => {
  24. console.log("beforeEach",to);
  25. const token = localStorage.token;
  26. if(to.path == "/order"){
  27. if(!token){
  28. alert("请先登陆");
  29. router.push("/login");
  30. }
  31. }
  32. next();
  33. })
  34. export default router;
App.vue
  1. <template>
  2. <div id="app">
  3. <mz-header></mz-header>
  4. <mz-menu></mz-menu>
  5. <router-view class="content"></router-view>
  6. </div>
  7. </template>
  8. <script>
  9. import Header from "@/components/Header";
  10. import Menu from "@/components/Menu";
  11. export default {
  12. name: "App",
  13. data(){
  14. return {
  15. };
  16. },
  17. methods:{
  18. },
  19. components:{
  20. [Header.name]:Header,
  21. [Menu.name]:Menu
  22. }
  23. }
  24. </script>
  25. <style>
  26. *{margin:0;padding:0;list-style:none;box-sizing: border-box;}
  27. html,body{width:100%;}/*overflow: hidden; */
  28. a{ text-decoration: none; font-size:12px; color: #000;}
  29. .fl{float: left;}
  30. .fr{float: right;}
  31. #app {
  32. width:375px; -height: 100%; background: #ccc; margin: 0 auto;
  33. }
  34. .content{padding-top:50px;}
  35. </style>
Header.vue
  1. <template>
  2. <div class="mz-home">
  3. <mz-banner></mz-banner>
  4. <!-- <mz-film type="now-playing"></mz-film>
  5. <mz-film type="coming-soon"></mz-film> -->
  6. <mz-film v-for="(item,index) in arr" :key="index" :type="item"></mz-film>
  7. </div>
  8. </template>
  9. <script>
  10. import {mapActions,mapMutations,mapState,mapGetters} from "vuex";
  11. import Swiper from "swiper";
  12. import "swiper/dist/css/swiper";
  13. import Banner from "./Banner";
  14. import Film from "./Film";
  15. import Vue from 'vue';
  16. export default {
  17. name: "mz-home",
  18. data() {
  19. return {
  20. arr:["now-playing","coming-soon"]
  21. }
  22. },
  23. methods:{
  24. ...mapActions({change:"changeAction"}),
  25. },
  26. computed:{
  27. },
  28. components:{
  29. [Banner.name]:Banner,
  30. [Film.name]:Film,
  31. },
  32. created(){
  33. this.change()
  34. }
  35. }
  36. </script>
  37. <style>
  38. .swiper-container {width: 375px;height: 210px;}
  39. .swiper-container img{width: 100%;height: 100%;}
  40. .film{padding:17px;padding-top: 18px;}
  41. .film li{height:240px; background: yellow;margin-bottom:17px;}
  42. .film li img{width: 100%;height: 100%;}
  43. </style>
Home.vue
  1. <template>
  2. <div class="mz-home">
  3. <mz-banner></mz-banner>
  4. <!-- <mz-film type="now-playing"></mz-film>
  5. <mz-film type="coming-soon"></mz-film> -->
  6. <mz-film v-for="(item,index) in arr" :key="index" :type="item"></mz-film>
  7. </div>
  8. </template>
  9. <script>
  10. import {mapActions,mapMutations,mapState,mapGetters} from "vuex";
  11. import Swiper from "swiper";
  12. import "swiper/dist/css/swiper";
  13. import Banner from "./Banner";
  14. import Film from "./Film";
  15. import Vue from 'vue';
  16. export default {
  17. name: "mz-home",
  18. data() {
  19. return {
  20. arr:["now-playing","coming-soon"]
  21. }
  22. },
  23. methods:{
  24. ...mapActions({change:"changeAction"}),
  25. },
  26. computed:{
  27. },
  28. components:{
  29. [Banner.name]:Banner,
  30. [Film.name]:Film,
  31. },
  32. created(){
  33. this.change()
  34. }
  35. }
  36. </script>
  37. <style>
  38. .swiper-container {width: 375px;height: 210px;}
  39. .swiper-container img{width: 100%;height: 100%;}
  40. .film{padding:17px;padding-top: 18px;}
  41. .film li{height:240px; background: yellow;margin-bottom:17px;}
  42. .film li img{width: 100%;height: 100%;}
  43. </style>
Banner.vue
  1. <template>
  2. <div>
  3. <!-- 轮播 https://m.maizuo.com/v4/api/billboard/home?__t=1533018029083-->
  4. <div class="swiper-container">
  5. <div class="swiper-wrapper">
  6. <div class="swiper-slide" v-for="item in arr" :key="item.id">
  7. <img :src="item.imageUrl" />
  8. </div>
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import Swiper from "swiper";
  15. import "swiper/dist/css/swiper";
  16. export default {
  17. name: 'mz-banner',
  18. data () {
  19. return {
  20. arr:[],
  21. }
  22. },
  23. created(){
  24. // https://m.maizuo.com/v4/api/billboard/home?__t=1533018029083
  25. let url = "http://localhost:9000/mz/v4/api/billboard/home";
  26. this.$http.get(url,{params:{__t:Date.now()}}).then(res=>{
  27. this.arr = res.data.data.billboards;
  28. });
  29. },
  30. updated(){
  31. new Swiper (".swiper-container",{loop: true});
  32. }
  33. }
  34. </script>
  35. <!-- Add "scoped" attribute to limit CSS to this component only -->
  36. <style scoped>
  37. </style>
Menu.vue
  1. <template>
  2. <div class="mz-menu">
  3. <transition name="slideLeft">
  4. <ul v-show="isShow" @click="show" >
  5. <router-link tag="li" v-for="item in arr" :to="item" :key="item.id">{{item.content}}</router-link>
  6. </ul>
  7. </transition>
  8. <transition name="fade">
  9. <div v-show="isShow" class="mask" @click="show"></div>
  10. </transition>
  11. </div>
  12. </template>
  13. <script>
  14. import {mapActions,mapMutations,mapState,mapGetters} from "vuex";
  15. export default {
  16. name: "mz-menu",
  17. data () {
  18. return {
  19. arr:[
  20. {id:Math.random(),content:"首页",path:"/home",name:"home"},
  21. {id:Math.random(),content:"影片",path:"/filmlist",name:"filmlist"},
  22. {id:Math.random(),content:"影院",path:"/cinema",name:"cinema"},
  23. {id:Math.random(),content:"商城",path:"/home",name:"home"},
  24. {id:Math.random(),content:"我的",path:"/login",name:"login"},
  25. {id:Math.random(),content:"卖座卡",path:"/card",name:"card"},
  26. ],
  27. }
  28. },
  29. computed:{
  30. ...mapState({isShow:"isShow"})
  31. // isShow(){
  32. // return this.$store.state.isShow;
  33. // }
  34. },
  35. methods:{
  36. ...mapMutations({show:"showMutation"}),
  37. // show(){
  38. // this.$store.commit("showMutation");
  39. // }
  40. },
  41. created(){
  42. }
  43. }
  44. </script>
  45. <!-- Add "scoped" attribute to limit CSS to this component only -->
  46. <style scoped>
  47. .mz-menu {position:fixed;left:0;top:50px;z-index:1000; -height: 100%; width:265px; }
  48. .mz-menu ul{width:265px;background: #282828;position:fixed;left:0;top:50px;right:0;bottom:0; z-index:2 ; -overflow: hidden;border-top: 1px solid #666;
  49. }
  50. .mz-menu li{width:100%;
  51. height:50px; line-height:50px;color: #9a9a9a;
  52. font-size: 14px; padding: 0 16px;border-bottom: 1px dotted #333;
  53. }
  54. .mask{
  55. position: fixed;top: 0;bottom: 0; left: 0; right: 0;z-index: 1;
  56. background: rgba(0,0,0,0.5);
  57. }
  58. /* .fade-enter,.fade-leave-to{opacity: 0;}
  59. .fade-enter-active,.fade-leave-active{ transition: 1s all ease;}
  60. .fade-enter-to,.fade-leave{opacity: 1;} */
  61. </style>
Film.vue
  1. <template>
  2. <div class="mz-film">
  3. <!-- 正在热映 https://m.maizuo.com/v4/api/film/now-playing?__t=1533018029103&page=1&count=5 -->
  4. <!-- 即将上映 https://m.maizuo.com/v4/api/film/coming-soon?__t=1533018029121&page=1&count=3 -->
  5. <ul class="film">
  6. <router-link tag="li" :to="{name:'filmdetail',params:{id:item.id}}" v-for="item in arr" :key="item.id">
  7. <img :src="item.cover.origin">
  8. </router-link>
  9. </ul>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. name: "mz-film",
  15. props:["type"],
  16. data () {
  17. return {
  18. arr:[]
  19. }
  20. },
  21. methods:{
  22. getFilms(){//now-playing | coming-soon
  23. let params = {__t:Date.now(),page:1,count:5};
  24. let url = `http://localhost:9000/mz/v4/api/film/${this.type}`;
  25. this.$http.get(url,{params}).then(res=>{
  26. this.arr = res.data.data.films;
  27. });
  28. }
  29. },
  30. created(){
  31. this.getFilms();
  32. },
  33. }
  34. </script>

16.vue-cli跨域,swiper,移动端项目的更多相关文章

  1. VUE SpringCloud 跨域资源共享 CORS 详解

    VUE  SpringCloud 跨域资源共享 CORS 详解 作者:  张艳涛 日期: 2020年7月28日 本篇文章主要参考:阮一峰的网络日志 » 首页 » 档案 --跨域资源共享 CORS 详解 ...

  2. vue解决跨域问题

    vue解决跨域问题 vue跨域解决方法和小总结 vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报“No 'Access-Control-Allow ...

  3. vue实现跨域请求的设置

    vue实现跨域请求,需要在vue.config.js里添加以下设置 proxy: { '/service/rest': { target: 'http://localhost:8080/autotab ...

  4. vue resource 携带cookie请求 vue cookie 跨域

    vue resource 携带cookie请求 vue cookie 跨域 1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm instal ...

  5. Vue的跨域设置

    1.在使用vue开发的时候经常要涉及到跨域的问题,其实在vue cli中是有我们设置跨域请求的文件的. 2.当跨域无法请求的时候我们可以修改工程下config文件夹下的index.js中的dev:{} ...

  6. django+vue实现跨域

    版本 Django 2.2.3 Python 3.8.8 djangorestframework 3.13.1 django-cors-headers 3.11.0 django实现跨域 说明:此处方 ...

  7. vue + vue-resource 跨域访问

    使用vue + vue-resource进行数据提交,后台使用RESTful API的方式存取数据,搞了一天,终于把后台搞好了.进行联合调试时,数据不能提交,报403错误: XMLHttpReques ...

  8. 如何实现vue前端跨域,proxyTable解决开发环境前端跨域问题

    在开发环境与后端调试的时候难免会遇到跨域问题,很多人说跨域交给后端解决就好了. 其实不然,前端也有很多方法可以解决跨域,方便也快捷. 常见的有nginx转发.node代理. 在vue项目中常用的是pr ...

  9. vue axios跨域

    现在应用都是前后端分离,这也造成前端在调用接口时出现跨域问题,在控制台会这样提示 ,如果有类似于此图的提示,就已经表明你的接口调用出现了跨域问题,此文章是我对于vue跨域其中一种方式的一些经验,如果错 ...

随机推荐

  1. Jsoup的简易使用示例

    http://www.open-open.com/jsoup/parsing-a-document.htm 测试用网页 <!doctype html> <!-- http://jwc ...

  2. Lua MD5加密字符串

    function md5_sumhexa(k) local md5_core = require "md5.core" k = md5_core.sum(k) return (st ...

  3. hdu5299 Circles Game

    Circles Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  4. Avizo/Amira应用 - 如何计算面孔率

    对于在Avizo或Amira中如何计算孔隙率,这个太简单,完成孔隙和整体材料的识别,再利用Volume Fraction计算即可获得,这里说的是每一层的面孔率如何计算? 数据导入,选取一个简单的过滤处 ...

  5. C#之值类型和引用类型

    本文意在巩固基础知识,并不是对其进行深入剖析,还望理解.本文是对此项知识的整理文,有些内容来源于网络,其他为博主原创,所以难免会有一些小得瑕疵,敬请谅解.所有示例均是博主测试过的,如有转载请标明出处, ...

  6. 【Linux】关于ffmpeg的一些常见用法

    一.FFmpeg简介 FFmpeg是一款非常快速的视频和音频转换器, 是开源项目 FFmpeg (Fast Forward moving pictures expert group) 的命令行程序. ...

  7. 最新的Delphi版本号对照

    The CompilerVersion constant identifies the internal version number of the Delphi compiler. It is de ...

  8. C#反射实现 C# 反射 判断类的延伸类型 使用代码生成工具Database2Sharp快速生成工作流模块控制器和视图代码 C# ADO.NET的SqlDataReader对象,判断是否包含指定字段 页面中添加锚点的几种方式 .net 简单实用Log4net(多个日志配置文件) C# 常用小点

    C#反射实现   一.反射概念: 1.概念: 反射,通俗的讲就是我们在只知道一个对象的内部而不了解内部结构的情况下,通过反射这个技术可以使我们明确这个对象的内部实现. 在.NET中,反射是重要的机制, ...

  9. linux内核剖析(六)Linux系统调用详解(实现机制分析)

    本文介绍了系统调用的一些实现细节.首先分析了系统调用的意义,它们与库函数和应用程序接口(API)有怎样的关系.然后,我们考察了Linux内核如何实现系统调用,以及执行系统调用的连锁反应:陷入内核,传递 ...

  10. SNF快速开发平台2018-移动端代码生成器已发布

    各位小伙伴期待已久的移动端已经推出,在此基础上我们又进行配套了代码生成器,以达到高速开发,简化代码等优点. 当然也需要有强大的组件库及标准程序的支撑,同时要有强大的后台做后盾来达到移动端强大功能的施展 ...