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. 【Vue课堂】Vue.js 父子组件之间通信的十种方式

    这篇文章介绍了Vue.js 父子组件之间通信的十种方式,不管是初学者还是已经在用 Vue 的开发者都会有所收获.无可否认,现在无论大厂还是小厂都已经用上了 Vue.js 框架,简单易上手不说,教程详尽 ...

  2. 三十、Linux 进程与信号——信号的概念及 signal 函数

    30.1 信号的基本概念 信号(signal)机制是Linux 系统中最为古老的进程之间的通信机制,解决进程在正常运行过程中被中断的问题,导致进程的处理流程会发生变化 信号是软件中断 信号是异步事件 ...

  3. dubbo 初探

    dubbo官网:http://dubbo.io Dubbo背景和简介(摘自 http://blog.csdn.net/noaman_wgs/article/details/70214612) Dubb ...

  4. c# 读取excels

    DataTable ExcelTable;            DataSet ds = new DataSet();            //Excel 文件一般都保存为统一的xls的连接  其 ...

  5. ue4 编辑器记录

    Matinee 编辑器 菜单:Add New Empty Group->选择要变动的Actor->菜单:Add Actor->菜单:Add Key->变更Actor属性-> ...

  6. Python 17 web框架&Django

    本节内容 1.html里面的正则表达式 2.web样式简介 3.Django创建工程 Html里的正则表达式 test 用来判断字符串是否符合规定的正则       rep.test('....')  ...

  7. Ajax——从服务器获取各种文件

    ajax.js内容 function ajax(url,fnWin,fnFaild){ //1.创建ajax对象 var xhr = window.XMLHttpRequest ? new XMLHt ...

  8. proxysql 系列 ~ 读写分离核心功能

    一 相关表介绍 1 mysql_user 列表配置    1 username && password 账号密码    2 default_hostgroup 默认的组ID2 mysq ...

  9. Typecho反序列化导致前台 getshell 漏洞复现

    Typecho反序列化导致前台 getshell 漏洞复现 漏洞描述: Typecho是一款快速建博客的程序,外观简洁,应用广泛.这次的漏洞通过install.php安装程序页面的反序列化函数,造成了 ...

  10. 20165237 2017-2018-2 《Java程序设计》第7周学习总结

    20165237 2017-2018-2 <Java程序设计>第7周学习总结 教材学习内容总结 1.MySQL数据库管理系统,简称MySQL,是世界上最流行的开源数据库管理系统. 2.启动 ...