如何解决无法读取Vue中未定义的属性“默认值”?

时间:2020-08-24 11:20:22

标签: vue.js

我正在vue应用程序中设置默认标头,但是在加载应用程序时会显示错误。

main.js?56d7:14未捕获的TypeError:无法读取未定义的属性“默认值”

enter image description here

代码

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: routes
  namespace: app1

spec:
  entryPoints:
    - websecure
    - web

  routes:
  - match: Host(`test.app1.com`)
    kind: Rule
    services:
    - name: test-service
      port: 8080
  tls:
    store:
      name: default

1 个答案:

答案 0 :(得分:1)

我根据您的问题制作了一个有效的Codepen。 对于您的情况,您需要创建axios客户端。 请检查该密码笔。 https://codepen.io/endmaster0809/pen/VwaPGzr

let apiClient = axios.create({
   baseURL: "https://jsonplaceholder.typicode.com",
   headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
   }
})

const token = "testtoken";
if (token) {
   apiClient.defaults.headers.common["Authorization"] = token;  
}

Vue.prototype.$http = apiClient;