将Vue组件插入到HTML甚至.blade(Laravel)文件中。

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

Inserting vue component into Html or even .blade (Laravel) files

问题

I'm a backend developer who knows a little bit of jQuery, and I'm struggling to insert a VUE 3 datepicker into an HTML page.
我是一个后端开发人员,了解一些jQuery,但我在将VUE 3日期选择器插入HTML页面时遇到了困难。

I understand that I would need to study frontend development more deeply, but at the moment, I can't afford to start from scratch to understand how this implementation works.
我明白我需要更深入地学习前端开发,但目前我无法从头开始了解这个实现是如何工作的。

I would like to use this component: vue3datepicker.com within an HTML file.
我想在HTML文件中使用这个组件:vue3datepicker.com。

I have read the component's documentation, asked in the GPT chat, in some forums I participate in, and searched relentlessly on Google and DuckDuckGo for how to implement third-party components in "static" HTML, but so far, none of the answers have helped me understand how to implement it.
我已经阅读了组件的文档,在GPT聊天中询问了,在一些我参与的论坛上询问了,并在Google和DuckDuckGo上不断搜索如何在“静态”HTML中实现第三方组件,但到目前为止,没有一个答案帮助我理解如何实现它。

In the section https://vue3datepicker.com/installation/, they mention some installation examples, but I'm more lost than a blind person in a shooting.
在https://vue3datepicker.com/installation/部分,他们提到了一些安装示例,但我比一个盲人在射击中还要迷失。

If I add the CDN, do I necessarily need to use the import for something else? (i still don't understand well npm and build steps)
如果我添加CDN,是否必须使用import导入其他内容?(我仍然不太理解npm和构建步骤)

I will leave an example of the code I tried to do here, but it is giving me an error:
我会在这里留下我尝试做的代码示例,但它给了我一个错误:

Vue warn: Failed to resolve component: vuedatepicker
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
at

Vue warn: Property "date" was accessed during render but is not defined on instance.
at

Vue警告:无法解析组件:vuedatepicker
如果这是一个本地自定义元素,请确保通过compilerOptions.isCustomElement将其从组件解析中排除。
中。

Vue警告:在渲染期间访问了属性“date”,但在实例上未定义。
中。

<!doctype html>
<html lang="en">

<head>
  <title>Title</title>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS v5.2.1 -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">

    <script src="https://unpkg.com/vue@latest"></script>
    <script src="https://unpkg.com/@vuepic/vue-datepicker@latest"></script>
    <link rel="stylesheet" href="https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css">

</head>

<body>
  <header>
    <!-- place navbar here -->
  </header>
  <main>

    <div id="app">
        <template>
            <VueDatePicker v-model="date"></VueDatePicker>
          </template>
    </div>
      
  </main>
  <footer>
    <!-- place footer here -->
  </footer>


</body>

<script>
    const app = Vue.createApp({
        components: { Datepicker: VueDatePicker },
    }).mount("#app");
</script>

</html>

Here some examples working in official doc https://vue3datepicker.com/props/modes-configuration/
这里有一些在官方文档中工作的示例https://vue3datepicker.com/props/modes-configuration/。

英文:

I'm a backend developer who knows a little bit of jQuery, and I'm struggling to insert a VUE 3 datepicker into an HTML page.
I understand that I would need to study frontend development more deeply, but at the moment, I can't afford to start from scratch to understand how this implementation works.

I would like to use this component: vue3datepicker.com within an HTML file.

I have read the component's documentation, asked in the GPT chat, in some forums I participate in, and searched relentlessly on Google and DuckDuckGo for how to implement third-party components in "static" HTML, but so far, none of the answers have helped me understand how to implement it.

In the section https://vue3datepicker.com/installation/, they mention some installation examples, but I'm more lost than a blind person in a shooting.

If I add the CDN, do I necessarily need to use the import for something else? (i still don't understand well npm and build steps)

I will leave an example of the code I tried to do here, but it is giving me an error:

Vue warn: Failed to resolve component: vuedatepicker
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
at &lt;App&gt;

Vue warn: Property "date" was accessed during render but is not defined on instance.
at &lt;App&gt;

&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;

&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;!-- Required meta tags --&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;

  &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;
    integrity=&quot;sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT&quot; crossorigin=&quot;anonymous&quot;&gt;

    &lt;script src=&quot;https://unpkg.com/vue@latest&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest&quot;&gt;&lt;/script&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css&quot;&gt;

&lt;/head&gt;

&lt;body&gt;
  &lt;header&gt;
    &lt;!-- place navbar here --&gt;
  &lt;/header&gt;
  &lt;main&gt;

    &lt;div id=&quot;app&quot;&gt;
        &lt;template&gt;
            &lt;VueDatePicker v-model=&quot;date&quot;&gt;&lt;/VueDatePicker&gt;
          &lt;/template&gt;
    &lt;/div&gt;
      
  &lt;/main&gt;
  &lt;footer&gt;
    &lt;!-- place footer here --&gt;
  &lt;/footer&gt;


&lt;/body&gt;

&lt;script&gt;
    const app = Vue.createApp({
        components: { Datepicker: VueDatePicker },
    }).mount(&quot;#app&quot;);
&lt;/script&gt;

&lt;/html&gt;

Here some examples working in oficial doc https://vue3datepicker.com/props/modes-configuration/

答案1

得分: 1

在上面的代码片段中,您不需要使用模板标签,而是需要调用Datepicker而不是VueDatePicker。纠正后的代码如下:

<!doctype html>
<html lang="en">

<head>
  <title>Title</title>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS v5.2.1 -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">

  <script src="https://unpkg.com/vue@latest"></script>
  <script src="https://unpkg.com/@vuepic/vue-datepicker@latest"></script>
  <link rel="stylesheet" href="https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css">

</head>

<body>
  <header>
    <!-- place navbar here -->
  </header>
  <main>

    <div id="app">
      <Datepicker v-model="date"></Datepicker>
    </div>

  </main>
  <footer>
    <!-- place footer here -->
  </footer>
</body>
</html>

请注意,上面的代码已进行了修正,不再使用模板标签,并使用了Datepicker而不是VueDatePicker。

英文:

In the above code snippet you don't need the template tag and you have to call Datepicker instead of VueDatePicker. Code after correction:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const app = Vue.createApp({
        components: { Datepicker: VueDatePicker },
        data() {
        return {
         date: &#39;&#39;
        }
       }
    }).mount(&quot;#app&quot;);

<!-- language: lang-html -->

&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;

&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;!-- Required meta tags --&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;

  &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;
    integrity=&quot;sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT&quot; crossorigin=&quot;anonymous&quot;&gt;

    &lt;script src=&quot;https://unpkg.com/vue@latest&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest&quot;&gt;&lt;/script&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css&quot;&gt;

&lt;/head&gt;

&lt;body&gt;
  &lt;header&gt;
    &lt;!-- place navbar here --&gt;
  &lt;/header&gt;
  &lt;main&gt;

    &lt;div id=&quot;app&quot;&gt;
        &lt;Datepicker v-model=&quot;date&quot;&gt;&lt;/Datepicker&gt;
    &lt;/div&gt;

  &lt;/main&gt;
  &lt;footer&gt;
    &lt;!-- place footer here --&gt;
  &lt;/footer&gt;
&lt;/body&gt;

</html>

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月11日 14:15:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76659150.html
匿名

发表评论

匿名网友

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

确定