VueJS 3与Pinia无需使用npm。

huangapple go评论58阅读模式
英文:

VueJS 3 with Pinia without npm

问题

我真的现在非常绝望。在文档中没有找到答案,Google 搜索结果中也没有找到答案,这是一个简单的问题:如何在 VUE 应用程序中安装/导入 PINIA。

让我们创建一个基本的 VUE 应用程序:

<div id="app">{{ message }}</div>

<script type="module">
  import { createApp, ref } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';

  // 这里是问题所在
  import { createPinia } from 'https://unpkg.com/pinia@2/dist/pinia.esm-browser.js';

  const pinia = createPinia();

  createApp({
    setup() {
      const message = ref('Hello Vue!');
      return {
        message
      };
    }
  }).use(pinia).mount('#app');
</script>

我的问题:

如何将 pinia 安装到此应用程序中?正确的 URL 是什么?

我不想使用 npm 安装... 只需要简单的 JavaScript 代码,没有本地服务器,没有其他东西。

我不是在制作服务器应用程序,我想要一个在浏览器中运行的 JavaScript 应用程序。

有人能否给我发送一个导入 pinia 的示例应用程序?

英文:

I'm really desperate now. Nowhere in the documentation, nowhere on google results can I find an answer to a simple question: how to install/import PINIA in a VUE application.

Lets have basic VUE app:

&lt;div id=&quot;app&quot;&gt;{{ message }}&lt;/div&gt;

&lt;script type=&quot;module&quot;&gt;
  import { createApp, ref } from &#39;https://unpkg.com/vue@3/dist/vue.esm-browser.js&#39;

    // HERE IS THE PROBLEM
    import { pinia } from &#39;https:WHAT-URT-TO-USE-????&#39;

  createApp({
    setup() {
      const message = ref(&#39;Hello Vue!&#39;)
      return {
        message
      }
    }
  }).mount(&#39;#app&#39;)
&lt;/script&gt;

My question:

how to install pinia to this app? what is the right URL?

I don't want any mpm install... just simple js code, no local server, nothing like that

I'm not making a server application, I want a JS application that runs in the browser

Can someone send me a sample application where pinia is imported?

答案1

得分: 1

大多数通过npm安装的浏览器/客户端依赖包,也可以在unpkg上找到。我看到您已经从unpkg使用了Vue包,所以您可以以相同的方式使用Pinia,使用以下URL:https://unpkg.com/pinia/index.js。然后导入的方式只是:

import { createPinia, PiniaVuePlugin } from 'https://unpkg.com/pinia/index.js'

提示:要通过unpkg浏览包的文件,请使用此URL格式:https://unpkg.com/browse/<package_name>/,例如https://unpkg.com/browse/pinia/。
请注意,末尾的斜杠很重要,确保不要漏掉它。

英文:

Most browser/client-side packages you install via npm, you can also find them from unpkg. I see that you're already using the Vue package from unpkg, so you can use Pinia the same way with the URL: https://unpkg.com/pinia/index.js. The import approach is then just:

import { createPinia, PiniaVuePlugin } from &#39;https://unpkg.com/pinia/index.js&#39;

Tip: to browse the files of a package via unpkg, use this URL format: https://unpkg.com/browse/&lt;package_name&gt;/, e.g https://unpkg.com/browse/pinia/.
Note that the ending forward slash is important, make sure you don't leave it out.

huangapple
  • 本文由 发表于 2023年6月19日 00:17:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501483.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定