vue + typescript 项目 当 vue vue-router vuex 用 cdn 引入时 ts 会报错

项目为 vue-cli 3.0 构建
public/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>世说新语</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="https://unpkg.com/highlight.js/styles/solarized-light.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.4/lib/index.css">
  </head>
  <body>
    <noscript>
      <strong>We're sorry but blog-pwa doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router@3.0.1/dist/vue-router.min.js"></script>
    <script src="https://unpkg.com/vuex@2.2.1/dist/vuex.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vant@1.4/lib/vant.min.js"></script>
    <script src="https://unpkg.com/highlight.js@9.12.0/lib/highlight.js"></script>
    
    <!-- built files will be auto injected -->
  </body>
</html>

vue.config.js

externals: {
    'vue': 'Vue',
    'vuex': 'Vuex',
    'vue-router': 'VueRouter',
    'vant': 'vant'
}

但是项目一直报错找不到模块
比如

clipboard.png

阅读 2.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题