vue-fetch
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的更多相关文章
- 使用Vue cli3搭建一个用Fetch Api的组件
系列参考 ,英文原文参考 我的git代码: https://github.com/chentianwei411/Typeahead 目标: 建立一个输入关键字得到相关列表的组件,用Vuejs2和Fet ...
- VUE系列三:实现跨域请求(fetch/axios/proxytable)
1. 在 config/index.js 配置文件中配置proxyTable 'use strict' // Template version: 1.3.1 // see http://vuejs-t ...
- vue下axios和fetch跨域请求
1.在config的index.js下面进行常用跨域配置代码:proxyTable: { '/apis': { //使用"/api"来代替"http://xxxx.cn& ...
- vue 信使 ------fetch、axios
fetch 1.什么是fetch 相当于promise 必须写两个then 第一个then返回状态码 返回成json格式 第二个then返回json数据 2.使用方法 $ npm install fe ...
- Vue的fetch的概述和使用
Fetch基本概念 (前端小白,刚学习vue,写的不好或是不对,请各位大佬多多指正!感激不尽!) Fetch 是一个现代的概念, 等同于 XMLHttpRequest.它提供了许多与XMLHttpRe ...
- 运行ABP(asp.net core 3.X+Vue)提示'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。
创建ASP.NET Boilerplate,还原数据库和启动客户端 这里就略过,具体参考 ABP框架(asp.net core 2.X+Vue)模板项目学习之路(一) ASP.NET Boilerpl ...
- 05 . Vue前端交互,fetch,axios,以asyncawait方式调用接口使用及案例
目标 /* 1. 说出什么是前后端交互模式 2. 说出Promise的相关概念和用法 3. 使用fetch进行接口调用 4. 使用axios进行接口调用 5. 使用asynnc/await方式调用接口 ...
- 八 Vue学习 fetch请求
1:import {login, getAdminInfo} from '@/api/getData'(从api/getData.js中import login函数.) 看一下如下的getData.j ...
- vue中fetch请求
1. 请求方式:get 请求参数:menuName 返回的结果:data created(){ this._initPageData() }, methods:{ _initPageData(){ f ...
- vue中简单的数据请求 fetch axios
fetch 不需要额外的安装什么东西,直接就可以使用 fetch(url, { method:'post', headers: { 'Content-Type': 'application/x-www ...
随机推荐
- 使用 Quartz.NET 实现作业串行执行
Ø 前言 前两天,在公司的一个项目中编写 Windows 服务时,需求是当A服务运行完后,B服务才能运行,B服务运行后,C服务才能运行.因为B服务的数据依赖于A服务生成的数据,而C服务的数据又依赖于 ...
- springboot03-unittest mockmvc单元测试
整个项目结构: 定义user实体类 package com.mlxs.springboot.dto; import java.util.HashMap; import java.util.Map; / ...
- hashMap源码解析(五)
---恢复内容开始--- 首先抛出一个问题: 为什么hashMap一般使用String作为key? 这是我学习前辈们的博文时看到的一个问题,觉着很有意思,所以记录下来. 原因1: 我当时的第一反应是: ...
- Linux 查看系统版本和内核
查看系统内核版本 [root@11e71db4a00e /]# cat /proc/version Linux version -.el7.x86_64 (builder@kbuilder.dev.c ...
- 合肥学院第二届卓越IT-程序设计大赛E+J
E链接 小飞有nn的魔法纸片(可以变出糖果), 现在有m个人来找小飞玩游戏, 小飞希望用魔法纸片来使朋友们开心,纸片可以被随便裁剪,nn的魔法纸片可以裁剪成任意大小的小魔法纸片,小飞通过pubgoso ...
- LR-Controller 如何自定义显示虚拟用户状态
我们压测时,如何直观,实时地查看当前运行账号和迭代情况呢. 在运行脚本中添加一行代码就解决了~~~~~~~~~~~
- day 10 - 1 函数进阶
函数进阶 命名空间和作用域 命名空间 命名空间 有三种内置命名空间 —— python解释器 就是python解释器一启动就可以使用的名字存储在内置命名空间中 内置的名字在启动解释器的时候被加载进内存 ...
- 【try..catch..】【判断输入是否为空】【onchange事件】【onmouseover和onmouseout事件】【onmousedown和onmouseup事件】
1.try..catch.. <body><script>function myFunction(){try{ var x=document.getElementById(&q ...
- vue购物车实战项02
1.数据循环.绑定 v- 绑定的属性 都是变量 ( 小程序这块需要花括号 不同点) 2.列表点击 当绑定变量为一个对象的时候{} 属性根据里面的属性值 bool 值 是否返回 当前的属性 转化成cl ...
- jquery判断表单内容是否为空
//判断表单数据是否为空 var t = $('form').serializeArray(); $.each(t,function(i,item){ if(item['value'] == '') ...