File tree Expand file tree Collapse file tree 4 files changed +23
-23
lines changed Expand file tree Collapse file tree 4 files changed +23
-23
lines changed Original file line number Diff line number Diff line change 2929 <None Include =" $(SpaRoot)**" Exclude =" $(SpaRoot)node_modules\**" />
3030 </ItemGroup >
3131
32+ <ItemGroup >
33+ <None Remove =" ClientApp\src\plugins\axios.ts" />
34+ </ItemGroup >
35+
3236 <ItemGroup >
3337 <Content Include =" ClientApp\tsconfig.json" />
3438 </ItemGroup >
3741 <None Include =" README.md" />
3842 </ItemGroup >
3943
44+ <ItemGroup >
45+ <TypeScriptCompile Include =" ClientApp\src\plugins\axios.ts" />
46+ </ItemGroup >
47+
4048 <Target Name =" DebugEnsureNodeEnv" BeforeTargets =" Build" Condition =" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') " >
4149 <!-- Ensure Node.js is installed -->
4250 <Exec Command =" node --version" ContinueOnError =" true" >
Original file line number Diff line number Diff line change 11"use strict" ;
22
3- import Vue from 'vue' ;
4- import axios from "axios" ;
3+ import vue from 'vue' ;
4+ import axios , { AxiosInstance } from "axios" ;
55
66// Full config: https://github.com/axios/axios#request-config
77// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
@@ -39,23 +39,17 @@ _axios.interceptors.response.use(
3939 }
4040) ;
4141
42- Plugin . install = function ( Vue , options ) {
43- Vue . axios = _axios ;
44- window . axios = _axios ;
45- Object . defineProperties ( Vue . prototype , {
46- axios : {
47- get ( ) {
48- return _axios ;
49- }
50- } ,
51- $axios : {
52- get ( ) {
53- return _axios ;
54- }
55- } ,
56- } ) ;
57- } ;
42+ function AxiosPlugin ( Vue : typeof vue , options ?: any ) : void {
43+ Vue . prototype . $axios = _axios ;
44+ }
45+
46+ declare module 'vue/types/vue' {
47+ interface Vue {
48+ $axios : AxiosInstance ;
49+ }
50+ }
51+
52+ vue . use ( AxiosPlugin )
5853
59- Vue . use ( Plugin )
6054
6155export default Plugin ;
Original file line number Diff line number Diff line change 4848// an example of a Vue Typescript component using vue-property-decorator
4949import { Component , Vue } from ' vue-property-decorator' ;
5050import { Forecast } from ' ../models/Forecast' ;
51- import axios from ' axios' ;
5251
5352@Component ({})
5453export default class FetchDataView extends Vue {
@@ -78,7 +77,7 @@ export default class FetchDataView extends Vue {
7877
7978 private async fetchWeatherForecasts() {
8079 try {
81- const response = await axios .get <Forecast []>(' api/WeatherForecast' );
80+ const response = await this . $ axios .get <Forecast []>(' api/WeatherForecast' );
8281 this .forecasts = response .data ;
8382 } catch (e ) {
8483 this .showError = true ;
Original file line number Diff line number Diff line change 4646// an example of a Vue Typescript component using Vue.extend
4747import Vue from ' vue' ;
4848import { Forecast } from ' ../models/Forecast' ;
49- import axios from ' axios' ;
5049
5150export default Vue .extend ({
5251 data() {
@@ -75,7 +74,7 @@ export default Vue.extend({
7574 },
7675 async fetchWeatherForecasts() {
7776 try {
78- const response = await axios .get <Forecast []>(' api/WeatherForecast' );
77+ const response = await this . $ axios .get <Forecast []>(' api/WeatherForecast' );
7978 this .forecasts = response .data ;
8079 } catch (e ) {
8180 this .showError = true ;
You can’t perform that action at this time.
0 commit comments