vue.js 拒绝应用中的样式,因为其MIME类型(“text/html”)不是受支持的样式表MIME类型,并且启用了严格的MIME检查

brtdzjyr  于 2023-11-21  发布在  Vue.js
关注(0)|答案(1)|浏览(436)

我正试图开发一个谷歌网络应用程序,在后端使用谷歌表。
我想在vscode中进行本地开发,因为google apps中的编辑器非常有限。我也想使用vue 3。
为了设置我的devel env,我遵循了我在网上找到的the only tutorial。本教程使用Parcel
一切都很顺利,除了没有考虑到放置在每个视图组件的样式标记中的css。
我发现了一个使用内联样式的解决方案,但这是相当挑剔和令人沮丧的。
浏览器中的控制台告诉我:
拒绝应用来自“https://n-7y7vlmirjfpoibpjjmpw7rb4z2lf2rvl3foebnq-0lu-script.googleusercontent.com/index.7692ac92.css”的样式,因为其MIME类型(“text/html”)不是受支持的样式表MIME类型,并且启用了严格的MIME检查。
css文件是由我的package.json中定义的构建脚本生成的,如下所示:

  1. {
  2. "name": "newcompta",
  3. "version": "1.0.0",
  4. "description": "",
  5. "scripts": {
  6. "start": "nodemon --watch ./src -e html,js,vue --exec \"npm run build\"",
  7. "build": "parcel build ./src/index.html --dist-dir ./appsscript",
  8. "glogin": "clasp login",
  9. "glogout": "clasp logout",
  10. "gpull": "clasp pull",
  11. "gpush": "clasp push",
  12. "gcreate": "clasp create --title \"NEWCOMPTA\" --rootDir ./appsscript",
  13. "gstart" :"clasp push --watch "
  14. },
  15. "keywords": [],
  16. "author": "",
  17. "license": "ISC",
  18. "devDependencies": {
  19. "@google/clasp": "^2.4.2",
  20. "@parcel/transformer-vue": "^2.10.2",
  21. "@types/google-apps-script": "^1.0.77",
  22. "parcel": "^2.10.2"
  23. },
  24. "dependencies": {
  25. "nodemon": "^3.0.1",
  26. "vue": "^3.3.8"
  27. }
  28. }

字符串
我从头开始重新启动一个项目,以查看问题是否从一开始就存在,事实确实如此。
下面是一些极简项目的文件示例。

index.html

  1. <head>
  2. <meta charset="UTF-8" />
  3. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  5. <title>Document</title>
  6. </head>
  7. <body>
  8. <div id="app"></div>
  9. <script type="module">
  10. import "./index.js";
  11. </script>
  12. </body>
  13. </html>

App.vue

  1. <template>
  2. <Tabs>
  3. <Tab active="true" title="First Tab">
  4. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce gravida purus vitae vulputate commodo.
  5. </Tab>
  6. <Tab title="Second Tab">
  7. Cras scelerisque, dolor vitae suscipit efficitur, risus orci sagittis velit, ac molestie nulla tortor id augue.
  8. </Tab>
  9. <Tab title="Third Tab">
  10. Morbi posuere, mauris eu vehicula tempor, nibh orci consectetur tortor, id eleifend dolor sapien ut augue.
  11. </Tab>
  12. <Tab title="Fourth Tab">
  13. Aenean varius dui eget ante finibus, sit amet finibus nisi facilisis. Nunc pellentesque, risus et pretium hendrerit.
  14. </Tab>
  15. </Tabs>
  16. </template>
  17. <script setup>
  18. import {ref } from 'vue'
  19. import Tabs from './components/Tabs.vue'
  20. import Tab from './components/Tab.vue'
  21. const name =ref('Vue')
  22. </script>

index.js

  1. import {createApp} from "vue";
  2. import App from "./App.vue";
  3. const app = createApp(App);
  4. app.mount("#app");
  5. **Tab.vue**
  6. <script setup>
  7. import { ref, onMounted } from 'vue';
  8. const props = defineProps([ 'active' ]);
  9. </script>
  10. <template>
  11. <div class="tab" :class="(active == 'true') ? 'active' : ''" ref="tabs">
  12. <slot></slot>
  13. </div>
  14. </template>
  15. <style>
  16. .tab {
  17. display: none;
  18. }
  19. .tab.active {
  20. display: block;
  21. }
  22. </style>

标签.vue

  1. <script setup>
  2. import { ref, onMounted, reactive } from 'vue';
  3. const props = defineProps([ 'customClass' ]);
  4. let tabContainer = ref(null);
  5. let tabHeaders = ref(null);
  6. let tabs = ref(null);
  7. let activeTabIndex = ref(0);
  8. onMounted(() => {
  9. tabs.value = [ ...tabContainer.value.querySelectorAll('.tab') ];
  10. for(let x of tabs.value) {
  11. if(x.classList.contains('active')) {
  12. activeTabIndex = tabs.value.indexOf(x);
  13. }
  14. }
  15. })
  16. const changeTab = (index) => {
  17. activeTabIndex = index;
  18. for(let x of [...tabs.value, ...tabHeaders.value]) {
  19. x.classList.remove('active')
  20. }
  21. tabs.value[activeTabIndex].classList.add('active')
  22. tabHeaders.value[activeTabIndex].classList.add('active')
  23. }
  24. </script>
  25. <template>
  26. <div id="tabs-container" :class="customClass" ref="tabContainer">
  27. <div id="tab-headers">
  28. <ul>
  29. <!-- this shows all of the titles -->
  30. <li v-for="(tab, index) in tabs" :key="index" :class="activeTabIndex == index ? 'active' : ''" @click="changeTab(index)" ref="tabHeaders">{{ tab.title }}</li>
  31. </ul>
  32. </div>
  33. <!-- this is where the tabs go, in this slot -->
  34. <div id="active-tab">
  35. <slot></slot>
  36. </div>
  37. </div>
  38. </template>
  39. <style>
  40. #tab-headers ul {
  41. margin: 0;
  42. padding: 0;
  43. display: flex;
  44. border-bottom: 2px solid #ddd;
  45. }
  46. #tab-headers ul li {
  47. list-style: none;
  48. padding: 1rem 1.25rem;
  49. position: relative;
  50. cursor: pointer;
  51. }
  52. #tab-headers ul li.active {
  53. color: #008438;
  54. font-weight: bold;
  55. }
  56. #tab-headers ul li.active:after {
  57. content: '';
  58. position: absolute;
  59. bottom: -2px;
  60. left: 0;
  61. height: 2px;
  62. width: 100%;
  63. background: #008438;
  64. }
  65. #active-tab, #tab-headers {
  66. width: 100%;
  67. }
  68. #active-tab {
  69. padding: 0.75rem;
  70. }
  71. </style>


这就是
x1c 0d1x的数据

92vpleto

92vpleto1#

看着this tutorial on youtube,我终于明白了解决方案。不是直接推送构建的结果,你必须将构建的.js和.css文件转换为. js.html和. css.html,不仅更改它们的扩展名,还将它们的内容包含在脚本或样式标签中。教程提供了执行此转换的gas.js。
此外,您还应该用该固定内容替换index.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- <base target="_top"> -->
  5. <meta charset="utf-8" />
  6. <meta name="viewport" content="width=device-width,initial-scale=1" />
  7. <title>vuejs-gas-template</title>
  8. <?!= include('vue/app.css') ?>
  9. </head>
  10. <body>
  11. <div id="app"></div>
  12. <?!= include('vue/manifest.js') ?>
  13. <?!= include('vue/vendor.js') ?>
  14. <?!= include('vue/app.js') ?>
  15. </body>
  16. </html>

字符串
当然文件和文件夹的名称取决于你的应用程序使用什么。在我的情况下,我不再使用由包裹制成的锅炉板,而是根据上面引用的教程使用另一个锅炉板。

展开查看全部

相关问题