解決vue獲取spring boot數據是出現的跨域問題

vue:vue

1.執行:vue add axios 安裝插件java

2.添加初始化方法:ios

created(){spring

const _this = thisaxios

axios.get('url’).then(function(resp){springboot

_this.變量名 = resp.dataapp

})this

}url

3.v-for報錯的解決方法:插件

1)文件 –>首選項 –>設置 –>在搜索框中輸入:vetur.validation.template–>找到vetur.validation.template:true–>改成false

2)綁定 :key

springboot:

1.添加@Configuration註解

2.實現WebMvcConfigurer接口

3.從新addCorsMappings(CorsRegistry registry)方法

registry.addMapping( pathPattern:"/**")

.allowedOrigins("*")

.allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")

.allowCredentials(true)

.maxAge(3000)

.allowedHeaders("*");

第一次寫博客,不管是表達或是技術都不算成熟,但願每位查看者多多指點,願意與你們分享本身的發現和解決的每個問題。

— —我是一隻java小菜鳥,或許永遠飛不高,但我永遠渴望遠方!

相關文章
相關標籤/搜索