在nuxt.js页面中包含外部javascript文件

问题描述 投票:0回答:3

我有一个相对简单的问题。

我正在尝试在Nuxt.js中实现the widget from this codepen。>>

这是我的代码,如果我使用RAW HTML,它可以正常工作:

<!DOCTYPE html>
<html>
<head></head>
<body>
  <dev-widget data-username="saurabhdaware"></dev-widget>
  <script src="https://unpkg.com/[email protected]/dist/card.component.mjs" type="module"></script>
</body>

</html>

但是当我尝试在我的其中一个页面中的nuxt.js项目中包含此开发小部件时,它不起作用。

这是我的代码:

<template>
  <div class="container">

    <div>
        <dev-widget data-username="saurabhdaware"></dev-widget>
    </div>

  </div>
</template>

<script>

export default {
  layout: "default",
};
</script>

<script src="https://unpkg.com/[email protected]/dist/card.component.mjs" type="module"></script>

我不断收到错误:

Unknown custom element: < dev-widget >

知道我在做什么错吗?

我有一个相对简单的问题。我正在尝试从Nuxt.js中的此Codepen实现小部件。这是我的代码,如果我使用RAW HTML,它可以正常工作:<...>

javascript vue.js vuejs2 nuxt.js nuxt
3个回答
1
投票

您需要在nuxt.config.js中添加脚本。这是它的外观]


0
投票

这是您答案中的线索:“未知的自定义元素:”。


0
投票

@@ kiyuku1的答案会起作用,但是如果我们只想在一个nuxt.js页面中而不是在全局中包括一个js(或mjs)文件,那么这是一个完整的解决方案,它会起作用:

© www.soinside.com 2019 - 2024. All rights reserved.