gpt4 book ai didi

vue.js - 如何在IIS上运行vuejs文件

转载 作者:行者123 更新时间:2023-12-04 17:28:15 25 4
gpt4 key购买 nike

因此,我使用 vueJS 示例作为学习目的的演示,它使用 requirejs-vue 作为组件加载器。当我在 VS 代码的 Live-Server 扩展(一个简单的 http 服务器)上运行服务器时,它可以正常运行,没有任何问题。但是,当我在 Windows 8.1 的 IIS 服务器(版本 8.5)上运行此示例时,它通过 404 错误 app.vue 不存在。

Failed to load resource: the server responded with a status of 404 (Not Found)

在 Network devtool 中,我可以看到每个模块都已正确加载,*.vue 文件除外,

VueJS 示例: https://plnkr.co/edit/Y2cEa3?preview

正在使用的 IIS 的 Web 配置: https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

PS:我还运行了另一个使用 http-vue-loader 而不是 requirejs-vue 的示例,IIS 仍然抛出同样的错误。

最佳答案

我们需要为“.vue”扩展文件设置mimeType才能使用httpvueloader/requiresjs_vue
enter image description here
另外,我们可以手动将其添加到IIS可以识别的Web.Config文件中。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".vue" mimeType="application/javascript"/>
</staticContent>
</system.webServer>
</configuration>

如果问题仍然存在,请随时告诉我。

关于vue.js - 如何在IIS上运行vuejs文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61935036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com