16.vue-cli跨域,swiper,移动端项目
解决跨域:
1、后台 cors cnpm i -S cors
2、前端 jsonp
3、代理 webpack: myvue\config\index.js 找 proxyTable
proxyTable: {
"/anhao": {
target: "http://localhost:3000",
changeOrigin: true,
pathRewrite: {
//需要rewrite重写的, 如果在服务器端做了处理则可以不要这段
"^/anhao": ""
}
}
},
vue插件:
axios vue-axios vue2-animate vuex swiper
cnpm i -S axios vue2-animate vuex swiper
vuex swiper //轮播特效copy
移动端布局:rem
rem: r---> html em
html{font-size:100px;}
标准的字体大小 100 当前的字体的大小 rem?
------------------- = -------------------
表示视图的宽度 750 当前的视图的宽度 document.documentElement.clientWidth
320px 640px 750px 1250px
rem?= 100/750*clientWidth = clientWidth/(7.5|3.75) + "px";
<transition>
<div v-show="isShow"></div>
</transition>
vue--->vuex
1、直接调用mutations ----> commit
2、直接调用actions ---> dispatch
mai zuo wang:
首页,头部,菜单,banner图
Main.js:
import Vue from "vue";
import VueAxios from "vue-axios";
import Axios from "axios";
import App from "./App";
import store from "./store";
import router from "./router";
import "vue2-animate/dist/vue2-animate";
//Vue.prototype.$http = axios;//引入axios
Vue.use(VueAxios,Axios);//引入axios
Vue.config.productionTip = false;
/* eslint-disable no-new */
new Vue({
el: "#app",
router,
store,
components: { App },
template: "<App/>"
})
store/index.js
vuex的store配置
import Vue from "vue";
import Vuex from "vuex";
import Axios from "axios";
Vue.use(Vuex);
let store = new Vuex.Store({
state:{
isShow:false,
title:"",
},
getters:{},
mutations:{
showMutation(state,payload){
state.isShow = !state.isShow;
//console.log("payload",payload);
},
yingyuanMutation(state,payload){
state.title = "全部影院";
},
changeMutation(state,payload){
state.title = "卖座电影";
},
loginMutation(state,payload){
state.title = "登录";
},
},
actions:{
showAction({commit},payload){
commit("showMutation");
},
changeAction({commit},payload){
commit("changeMutation");
},
yingyuanAction({commit},payload){
commit("yingyuanMutation");
},
loginAction({commit},payload){
commit("loginMutation");
},
},
modules:{},
});
console.log(111111,store.state.title)
export default store;
router/index.js
路由配置js
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home';
import Login from '@/components/Login';
import City from '@/components/City';
import FilmList from "@/components/FilmList";
import FilmDetail from "@/components/FilmDetail";
import Cinema from "@/components/Cinema";
import Order from "@/components/Order";
Vue.use(Router)
const router = new Router({
routes: [
{path: '/',name: 'home',component: Home},
{path: '/login',name: 'login',component: Login},
{path: '/city',name: 'city',component: City},
{path: "/filmlist",name: "filmlist",component: FilmList},
{path: "/filmdetail/:id",name: "filmdetail",component: FilmDetail,props:true},
{path:"/cinema",name:"cinema",component:Cinema},
{path:"/order",name:"order",component:Order},
{path: "/*",redirect:"/"},
]
});
router.beforeEach((to, from, next) => {
console.log("beforeEach",to);
const token = localStorage.token;
if(to.path == "/order"){
if(!token){
alert("请先登陆");
router.push("/login");
}
}
next();
})
export default router;
App.vue
<template>
<div id="app">
<mz-header></mz-header>
<mz-menu></mz-menu>
<router-view class="content"></router-view>
</div>
</template>
<script>
import Header from "@/components/Header";
import Menu from "@/components/Menu";
export default {
name: "App",
data(){
return {
};
},
methods:{
},
components:{
[Header.name]:Header,
[Menu.name]:Menu
}
}
</script>
<style>
*{margin:0;padding:0;list-style:none;box-sizing: border-box;}
html,body{width:100%;}/*overflow: hidden; */
a{ text-decoration: none; font-size:12px; color: #000;}
.fl{float: left;}
.fr{float: right;}
#app {
width:375px; -height: 100%; background: #ccc; margin: 0 auto;
}
.content{padding-top:50px;}
</style>
Header.vue
<template>
<div class="mz-home">
<mz-banner></mz-banner>
<!-- <mz-film type="now-playing"></mz-film>
<mz-film type="coming-soon"></mz-film> -->
<mz-film v-for="(item,index) in arr" :key="index" :type="item"></mz-film>
</div>
</template>
<script>
import {mapActions,mapMutations,mapState,mapGetters} from "vuex";
import Swiper from "swiper";
import "swiper/dist/css/swiper";
import Banner from "./Banner";
import Film from "./Film";
import Vue from 'vue';
export default {
name: "mz-home",
data() {
return {
arr:["now-playing","coming-soon"]
}
},
methods:{
...mapActions({change:"changeAction"}),
},
computed:{
},
components:{
[Banner.name]:Banner,
[Film.name]:Film,
},
created(){
this.change()
}
}
</script>
<style>
.swiper-container {width: 375px;height: 210px;}
.swiper-container img{width: 100%;height: 100%;}
.film{padding:17px;padding-top: 18px;}
.film li{height:240px; background: yellow;margin-bottom:17px;}
.film li img{width: 100%;height: 100%;}
</style>
Home.vue
<template>
<div class="mz-home">
<mz-banner></mz-banner>
<!-- <mz-film type="now-playing"></mz-film>
<mz-film type="coming-soon"></mz-film> -->
<mz-film v-for="(item,index) in arr" :key="index" :type="item"></mz-film>
</div>
</template>
<script>
import {mapActions,mapMutations,mapState,mapGetters} from "vuex";
import Swiper from "swiper";
import "swiper/dist/css/swiper";
import Banner from "./Banner";
import Film from "./Film";
import Vue from 'vue';
export default {
name: "mz-home",
data() {
return {
arr:["now-playing","coming-soon"]
}
},
methods:{
...mapActions({change:"changeAction"}),
},
computed:{
},
components:{
[Banner.name]:Banner,
[Film.name]:Film,
},
created(){
this.change()
}
}
</script>
<style>
.swiper-container {width: 375px;height: 210px;}
.swiper-container img{width: 100%;height: 100%;}
.film{padding:17px;padding-top: 18px;}
.film li{height:240px; background: yellow;margin-bottom:17px;}
.film li img{width: 100%;height: 100%;}
</style>
Banner.vue
<template>
<div>
<!-- 轮播 https://m.maizuo.com/v4/api/billboard/home?__t=1533018029083-->
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="item in arr" :key="item.id">
<img :src="item.imageUrl" />
</div>
</div>
</div>
</div>
</template>
<script>
import Swiper from "swiper";
import "swiper/dist/css/swiper";
export default {
name: 'mz-banner',
data () {
return {
arr:[],
}
},
created(){
// https://m.maizuo.com/v4/api/billboard/home?__t=1533018029083
let url = "http://localhost:9000/mz/v4/api/billboard/home";
this.$http.get(url,{params:{__t:Date.now()}}).then(res=>{
this.arr = res.data.data.billboards;
});
},
updated(){
new Swiper (".swiper-container",{loop: true});
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
Menu.vue
<template>
<div class="mz-menu">
<transition name="slideLeft">
<ul v-show="isShow" @click="show" >
<router-link tag="li" v-for="item in arr" :to="item" :key="item.id">{{item.content}}</router-link>
</ul>
</transition>
<transition name="fade">
<div v-show="isShow" class="mask" @click="show"></div>
</transition>
</div>
</template>
<script>
import {mapActions,mapMutations,mapState,mapGetters} from "vuex";
export default {
name: "mz-menu",
data () {
return {
arr:[
{id:Math.random(),content:"首页",path:"/home",name:"home"},
{id:Math.random(),content:"影片",path:"/filmlist",name:"filmlist"},
{id:Math.random(),content:"影院",path:"/cinema",name:"cinema"},
{id:Math.random(),content:"商城",path:"/home",name:"home"},
{id:Math.random(),content:"我的",path:"/login",name:"login"},
{id:Math.random(),content:"卖座卡",path:"/card",name:"card"},
],
}
},
computed:{
...mapState({isShow:"isShow"})
// isShow(){
// return this.$store.state.isShow;
// }
},
methods:{
...mapMutations({show:"showMutation"}),
// show(){
// this.$store.commit("showMutation");
// }
},
created(){
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.mz-menu {position:fixed;left:0;top:50px;z-index:1000; -height: 100%; width:265px; }
.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;
}
.mz-menu li{width:100%;
height:50px; line-height:50px;color: #9a9a9a;
font-size: 14px; padding: 0 16px;border-bottom: 1px dotted #333;
}
.mask{
position: fixed;top: 0;bottom: 0; left: 0; right: 0;z-index: 1;
background: rgba(0,0,0,0.5);
}
/* .fade-enter,.fade-leave-to{opacity: 0;}
.fade-enter-active,.fade-leave-active{ transition: 1s all ease;}
.fade-enter-to,.fade-leave{opacity: 1;} */
</style>
Film.vue
<template>
<div class="mz-film">
<!-- 正在热映 https://m.maizuo.com/v4/api/film/now-playing?__t=1533018029103&page=1&count=5 -->
<!-- 即将上映 https://m.maizuo.com/v4/api/film/coming-soon?__t=1533018029121&page=1&count=3 -->
<ul class="film">
<router-link tag="li" :to="{name:'filmdetail',params:{id:item.id}}" v-for="item in arr" :key="item.id">
<img :src="item.cover.origin">
</router-link>
</ul>
</div>
</template>
<script>
export default {
name: "mz-film",
props:["type"],
data () {
return {
arr:[]
}
},
methods:{
getFilms(){//now-playing | coming-soon
let params = {__t:Date.now(),page:1,count:5};
let url = `http://localhost:9000/mz/v4/api/film/${this.type}`;
this.$http.get(url,{params}).then(res=>{
this.arr = res.data.data.films;
});
}
},
created(){
this.getFilms();
},
}
</script>
16.vue-cli跨域,swiper,移动端项目的更多相关文章
- VUE SpringCloud 跨域资源共享 CORS 详解
VUE SpringCloud 跨域资源共享 CORS 详解 作者: 张艳涛 日期: 2020年7月28日 本篇文章主要参考:阮一峰的网络日志 » 首页 » 档案 --跨域资源共享 CORS 详解 ...
- vue解决跨域问题
vue解决跨域问题 vue跨域解决方法和小总结 vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报“No 'Access-Control-Allow ...
- vue实现跨域请求的设置
vue实现跨域请求,需要在vue.config.js里添加以下设置 proxy: { '/service/rest': { target: 'http://localhost:8080/autotab ...
- vue resource 携带cookie请求 vue cookie 跨域
vue resource 携带cookie请求 vue cookie 跨域 1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm instal ...
- Vue的跨域设置
1.在使用vue开发的时候经常要涉及到跨域的问题,其实在vue cli中是有我们设置跨域请求的文件的. 2.当跨域无法请求的时候我们可以修改工程下config文件夹下的index.js中的dev:{} ...
- django+vue实现跨域
版本 Django 2.2.3 Python 3.8.8 djangorestframework 3.13.1 django-cors-headers 3.11.0 django实现跨域 说明:此处方 ...
- vue + vue-resource 跨域访问
使用vue + vue-resource进行数据提交,后台使用RESTful API的方式存取数据,搞了一天,终于把后台搞好了.进行联合调试时,数据不能提交,报403错误: XMLHttpReques ...
- 如何实现vue前端跨域,proxyTable解决开发环境前端跨域问题
在开发环境与后端调试的时候难免会遇到跨域问题,很多人说跨域交给后端解决就好了. 其实不然,前端也有很多方法可以解决跨域,方便也快捷. 常见的有nginx转发.node代理. 在vue项目中常用的是pr ...
- vue axios跨域
现在应用都是前后端分离,这也造成前端在调用接口时出现跨域问题,在控制台会这样提示 ,如果有类似于此图的提示,就已经表明你的接口调用出现了跨域问题,此文章是我对于vue跨域其中一种方式的一些经验,如果错 ...
随机推荐
- 招聘移动APP、接口、自动化、性能和安全方面的兼职测试讲师
只要您在移动APP.接口.自动化.性能和安全方面有丰富的测试经验,我们都欢迎您能加入我们,成为我们的兼职测试讲师,我们可以提供给您一份优厚的薪资,同时能在行业发展.企业培训.授课经验.出版专业著作等方 ...
- MediaInfo代码阅读
MediaInfo是一个用来分析媒体文件的开源工具. 支持的文件非常全面,基本上支持所有的媒体文件. 最近是在做HEVC开发,所以比较关注MediaInfo中关于HEVC的分析与处理. 从Meid ...
- Spring Boot参数校验
1. 概述 作为接口服务提供方,非常有必要在项目中加入参数校验,比如字段非空,字段长度限制,邮箱格式验证等等,数据校验常用到概念:JSR303/JSR-349: JSR303是一项标准,只提供规范不提 ...
- Win7 32位下cocos2dx android开发调试环境
1.使用环境 win7 32位 + vs2010 2.软件准备(下方绿色文字带链接) cocos2dx-v2.2.2 jdk7 android sdk android ndk adt bundle a ...
- 微软“小冰”识狗与人工神经网络(V)
实际上.微软早在2014年7月14日首次透露了一项雄心勃勃的研究计划"亚当计划"("Projrct Adam"),该项目是有关计算机视觉方面的研究项目,也就是后 ...
- Python性能分析
Python性能分析 https://www.cnblogs.com/lrysjtu/p/5651816.html https://www.cnblogs.com/cbscan/articles/33 ...
- 一个会学习(观察->活学->求变)的人,在任何领域都能变得强大无比
开始今天的话题之前,我说个小故事. 很早以前有一部美剧,叫<Hero>. 大概讲的是正反两派都是一群有超能力的人,彼此为了某个巨大的阴谋互相撕逼了十多集.虽然剧情很老套,但是让 ...
- Redis 学习之路 (011) - redis 多数据库
一台服务器上都快开启200个redis实例了,看着就崩溃了.这么做无非就是想让不同类型的数据属于不同的应用程序而彼此分开. 那么,redis有没有什么方法使不同的应用程序数据彼此分开同时又存储在相同的 ...
- Mssql Server2005中更改sa的用户名的多种方法
mssql安装上去时默认就是sa用户,大多数用户都会一直使用sa这个用户,这样数据库就存在很大的安全问题了,如果我们能把sa用户名修改,这样安全级别又高了一层哦,下面我们来看修改sa用户名的办法. ...
- 批量替换存储过程内容脚本sp_SqlReplace
开始 在数据库开发过程中,如果某一个表字段名被重命名.那么在使用到该字段的存储过程,对应的表字段名也要修改. 当存在多个存储都有使用该表字段,需要逐个去修改替换,是一件比较繁琐的事情,我们需要一个能实 ...