1.安装命令“

cnpm install --save isomorphic-fetch es6-promise

2.由于ie不支持Promise,所以需要安装promise-polyfill;

cnpm install promise-polyfill --save-exact

需要在index.js中引用

import Vue from 'vue'
import Router from 'vue-router'
import Promise from "promise-polyfill"; if(!window.Promise){
window.Promise = Promise;
}

3.使用

<template>
<div class="hello">
<h1 @click="getUrl">{{ msg }}</h1>
<router-link to="/test/one">testlinks</router-link>
<router-link to="/test/two" exact>testlinks1</router-link>
<router-link to="/user/one">testlinks2</router-link>
<transition :name="tranName">
<router-view></router-view>
</transition>
<ul>
<li v-for='item in items'>{{item.id}}</li>
</ul>
</div> </template> <script> require("es6-promise").polyfill();
require('isomorphic-fetch'); export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App',
tranName:'slide-left',
items:[]
}
},
created(){
let _this = this;
fetch('./src/static/data.json').then(function(res){
return res.json();
}).then(function(stories){
console.log(stories)
_this.items = stories;
}).then(function(err){
console.log(err)
})
},
methods:{
getUrl(){
console.log(1)
}
},
beforeRouteUpdate (to, from, next) {
const toDepth = to.path.split('/').length
const fromDepth = from.path.split('/').length
this.tranName = toDepth >= fromDepth ? 'slide-right' : 'slide-left'
next()
},
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-to /* .fade-leave-active in below version 2.1.8 */ {
opacity: 0
}
.slide-left-enter-active, .slide-right-leave-active {
transition: all .5s cubic-bezier(.55,0,.1,1);
}
.slide-left-enter, .slide-right-leave-active {
opacity: 0;
-webkit-transform: translate(30px, 0);
transform: translate(30px, 0);
}
.slide-left-leave-active, .slide-right-enter {
opacity: 0;
-webkit-transform: translate(-30px, 0);
transform: translate(-30px, 0);
}
</style>

vue-fetch的更多相关文章

  1. 使用Vue cli3搭建一个用Fetch Api的组件

    系列参考 ,英文原文参考 我的git代码: https://github.com/chentianwei411/Typeahead 目标: 建立一个输入关键字得到相关列表的组件,用Vuejs2和Fet ...

  2. VUE系列三:实现跨域请求(fetch/axios/proxytable)

    1. 在 config/index.js 配置文件中配置proxyTable 'use strict' // Template version: 1.3.1 // see http://vuejs-t ...

  3. vue下axios和fetch跨域请求

    1.在config的index.js下面进行常用跨域配置代码:proxyTable: { '/apis': { //使用"/api"来代替"http://xxxx.cn& ...

  4. vue 信使 ------fetch、axios

    fetch 1.什么是fetch 相当于promise 必须写两个then 第一个then返回状态码 返回成json格式 第二个then返回json数据 2.使用方法 $ npm install fe ...

  5. Vue的fetch的概述和使用

    Fetch基本概念 (前端小白,刚学习vue,写的不好或是不对,请各位大佬多多指正!感激不尽!) Fetch 是一个现代的概念, 等同于 XMLHttpRequest.它提供了许多与XMLHttpRe ...

  6. 运行ABP(asp.net core 3.X+Vue)提示'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。

    创建ASP.NET Boilerplate,还原数据库和启动客户端 这里就略过,具体参考 ABP框架(asp.net core 2.X+Vue)模板项目学习之路(一) ASP.NET Boilerpl ...

  7. 05 . Vue前端交互,fetch,axios,以asyncawait方式调用接口使用及案例

    目标 /* 1. 说出什么是前后端交互模式 2. 说出Promise的相关概念和用法 3. 使用fetch进行接口调用 4. 使用axios进行接口调用 5. 使用asynnc/await方式调用接口 ...

  8. 八 Vue学习 fetch请求

    1:import {login, getAdminInfo} from '@/api/getData'(从api/getData.js中import login函数.) 看一下如下的getData.j ...

  9. vue中fetch请求

    1. 请求方式:get 请求参数:menuName 返回的结果:data created(){ this._initPageData() }, methods:{ _initPageData(){ f ...

  10. vue中简单的数据请求 fetch axios

    fetch 不需要额外的安装什么东西,直接就可以使用 fetch(url, { method:'post', headers: { 'Content-Type': 'application/x-www ...

随机推荐

  1. 二十五、Linux 进程与信号---exec函数

    25.1 介绍 在用 fork 函数创建子进程后,子进程往往要调用一种 exec 函数以执行另一个程序 当进程调用一种 exec 函数时,该进程完全由新程序代换,替换原有进程的正文,而新程序则从其 m ...

  2. Play XML Entities

    链接:https://pentesterlab.com/exercises/play_xxe/course Introduction This course details the exploitat ...

  3. Java之@SuppressWarnings

    用了这个,MyEclipse里就不会报那些警告了,看起来漂亮多了 常用的:@SuppressWarnings("unchecked"),泛型@SuppressWarnings(&q ...

  4. 【blog】SpringBoot事务

    参考链接 http://www.cnblogs.com/xingzc/p/6029483.html

  5. asyncio模块中的Future和Task

      task是可以理解为单个coroutine,经过ensure_future方法处理而形成,而众多task所组成的集合经过asyncio.gather处理而形成一个future. 再不精确的粗略的说 ...

  6. i春秋 小漏洞也有大梦想

    i春秋上的课,提到了一些概念,学习并记录. 此文主要以了解概念为主,没有代码和实战. 水坑式攻击 百度定义: “水坑式攻击”,是指黑客通过分析被攻击者的网络活动规律,寻找被攻击者经常访问的网站的弱点, ...

  7. hsf

    参考文章: ----- 架构和框架的区别 1.HSF源码剖析 2.Http和RPC区别 3.分布式服务框架HSF 4.高并发架构系列:如何从0到1设计一个类Dubbo的RPC框架 5.HSF的原理分析 ...

  8. 在Python中用Selenium执行JavaScript

    Selenium自己不带浏览器, 需要与第三方浏览器结合在一起使用.例如在Firefox上运行Selenium. PhantomJS是一个"无头"浏览器. 它会把网站加载到内存并执 ...

  9. 【ARTS】01_18_左耳听风-20190311~20190317

    ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...

  10. 【转】Python 面向对象(初级篇)

    [转]Python 面向对象(初级篇) 51CTO同步发布地址:http://3060674.blog.51cto.com/3050674/1689163 概述 面向过程:根据业务逻辑从上到下写垒代码 ...