因此,出于学习目的,也使用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
。另外,我们可以手动将其添加到Web.Config
文件中,IIS可以识别该文件。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".vue" mimeType="application/javascript"/>
</staticContent>
</system.webServer>
</configuration>
随时让我知道问题是否仍然存在。