A Pen by GuoXi

Thumbnail
This awesome code was written by 1206189299, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 1206189299 ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  GuoXi</title>
  
  
  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/1206189299/a-pen-by-guoxi-pwLpdr */

/* ******************************************这是main.js******************************************** */
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router/index';
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import store from './store';
import VueLazyLoad from 'vue-lazyload'; 

Vue.config.productionTip = false
Vue.use(iView);
Vue.use(VueLazyLoad);
/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  template: '<App/>',
  components: { App },
})

export var saveDate ="";
     function getData(data){
               saveDate = data;
            }




/***************************************** 这是home.js************************************* */

export default {
	path:'/',
  redirect:'/main',
	name:'Home',
	component:home,
  children:[
       movieDetail,
  {
     path:'main',
     component:main
  } 
  ],
	beforeEnter:(to , before , next) => {

         if(Object.keys(store.state.home.homeData).length !==0){
         	store.commit(types.LOADING_FLAG, false);
         	next();
         	return;
         }
         store.commit(types.LOADING_FLAG,true);
         Promise.all([
               hotMovie(8,0),
               commingSoon(8,0),
               top250(8,0),
               usBox(8,0)
         	]).then((homeData) => {
         		store.commit(types.HOME_DATA,homeData);
         		store.commit(types.LOADING_FLAG,false);

         	})
         	next();
	}
}







/* ****************************这是jsonp.js *************************************************/
import {saveData} from '../main.js';
const Jsonp =  url => new Promise((resolve,reject) =>{

	         var script = document.createElement('script');
	         script.type="text/javascript";
	         script.src=url;
	         document.body.appendChild(script);
                 if(saveData){
                 	resolve(JSON.parse(data));
                 } else {
                 	reject('数据获取失败');
                 }

             

});

export const hotMovie = (count, start) =>
   Jsonp(`http://api.douban.com/v2/movie/in_theaters?count=${count}&start=${start}?callback=getData&callback=getData`);
// 即将上映
export const commingSoon = (count, start) =>
  Jsonp(`http://api.douban.com/v2/movie/coming_soon?count=${count}&start=${start}?callback=getData&callback=getData`);
// top250
export const top250 = (count, start) =>
  Jsonp(`http://api.douban.com/v2/movie/top250?count=${count}&start=${start}?callback=getData&callback=getData`);
// 北美票房榜
export const usBox = (count, start) =>
  Jsonp(`http://api.douban.com/v2/movie/us_box?count=${count}&start=${start}?callback=getData&callback=getData`);
// 当前电影详情信息
export const currentMovie = currentMovieId =>
  Jsonp(`http://api.douban.com/v2/movie/subject/${currentMovieId}?callback=getData&callback=getData`);
// 当前标签详情信息
export const getTagData = (tag, count, start) =>
  Jsonp(`http://api.douban.com/v2/movie/search?tag=${tag}&count=${count}&start=${start}?callback=getData&callback=getData`);

Comments