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

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

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”,但在实例上未定义。
中。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>Title</title>
  5. <!-- Required meta tags -->
  6. <meta charset="utf-8">
  7. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  8. <!-- Bootstrap CSS v5.2.1 -->
  9. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
  10. integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
  11. <script src="https://unpkg.com/vue@latest"></script>
  12. <script src="https://unpkg.com/@vuepic/vue-datepicker@latest"></script>
  13. <link rel="stylesheet" href="https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css">
  14. </head>
  15. <body>
  16. <header>
  17. <!-- place navbar here -->
  18. </header>
  19. <main>
  20. <div id="app">
  21. <template>
  22. <VueDatePicker v-model="date"></VueDatePicker>
  23. </template>
  24. </div>
  25. </main>
  26. <footer>
  27. <!-- place footer here -->
  28. </footer>
  29. </body>
  30. <script>
  31. const app = Vue.createApp({
  32. components: { Datepicker: VueDatePicker },
  33. }).mount("#app");
  34. </script>
  35. </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;

  1. &lt;!doctype html&gt;
  2. &lt;html lang=&quot;en&quot;&gt;
  3. &lt;head&gt;
  4. &lt;title&gt;Title&lt;/title&gt;
  5. &lt;!-- Required meta tags --&gt;
  6. &lt;meta charset=&quot;utf-8&quot;&gt;
  7. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;
  8. &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  9. &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;
  10. integrity=&quot;sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT&quot; crossorigin=&quot;anonymous&quot;&gt;
  11. &lt;script src=&quot;https://unpkg.com/vue@latest&quot;&gt;&lt;/script&gt;
  12. &lt;script src=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest&quot;&gt;&lt;/script&gt;
  13. &lt;link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css&quot;&gt;
  14. &lt;/head&gt;
  15. &lt;body&gt;
  16. &lt;header&gt;
  17. &lt;!-- place navbar here --&gt;
  18. &lt;/header&gt;
  19. &lt;main&gt;
  20. &lt;div id=&quot;app&quot;&gt;
  21. &lt;template&gt;
  22. &lt;VueDatePicker v-model=&quot;date&quot;&gt;&lt;/VueDatePicker&gt;
  23. &lt;/template&gt;
  24. &lt;/div&gt;
  25. &lt;/main&gt;
  26. &lt;footer&gt;
  27. &lt;!-- place footer here --&gt;
  28. &lt;/footer&gt;
  29. &lt;/body&gt;
  30. &lt;script&gt;
  31. const app = Vue.createApp({
  32. components: { Datepicker: VueDatePicker },
  33. }).mount(&quot;#app&quot;);
  34. &lt;/script&gt;
  35. &lt;/html&gt;

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

答案1

得分: 1

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

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>Title</title>
  5. <!-- Required meta tags -->
  6. <meta charset="utf-8">
  7. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  8. <!-- Bootstrap CSS v5.2.1 -->
  9. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"
  10. integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
  11. <script src="https://unpkg.com/vue@latest"></script>
  12. <script src="https://unpkg.com/@vuepic/vue-datepicker@latest"></script>
  13. <link rel="stylesheet" href="https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css">
  14. </head>
  15. <body>
  16. <header>
  17. <!-- place navbar here -->
  18. </header>
  19. <main>
  20. <div id="app">
  21. <Datepicker v-model="date"></Datepicker>
  22. </div>
  23. </main>
  24. <footer>
  25. <!-- place footer here -->
  26. </footer>
  27. </body>
  28. </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 -->

  1. const app = Vue.createApp({
  2. components: { Datepicker: VueDatePicker },
  3. data() {
  4. return {
  5. date: &#39;&#39;
  6. }
  7. }
  8. }).mount(&quot;#app&quot;);

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

  1. &lt;!doctype html&gt;
  2. &lt;html lang=&quot;en&quot;&gt;
  3. &lt;head&gt;
  4. &lt;title&gt;Title&lt;/title&gt;
  5. &lt;!-- Required meta tags --&gt;
  6. &lt;meta charset=&quot;utf-8&quot;&gt;
  7. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;
  8. &lt;!-- Bootstrap CSS v5.2.1 --&gt;
  9. &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;
  10. integrity=&quot;sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT&quot; crossorigin=&quot;anonymous&quot;&gt;
  11. &lt;script src=&quot;https://unpkg.com/vue@latest&quot;&gt;&lt;/script&gt;
  12. &lt;script src=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest&quot;&gt;&lt;/script&gt;
  13. &lt;link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/@vuepic/vue-datepicker@latest/dist/main.css&quot;&gt;
  14. &lt;/head&gt;
  15. &lt;body&gt;
  16. &lt;header&gt;
  17. &lt;!-- place navbar here --&gt;
  18. &lt;/header&gt;
  19. &lt;main&gt;
  20. &lt;div id=&quot;app&quot;&gt;
  21. &lt;Datepicker v-model=&quot;date&quot;&gt;&lt;/Datepicker&gt;
  22. &lt;/div&gt;
  23. &lt;/main&gt;
  24. &lt;footer&gt;
  25. &lt;!-- place footer here --&gt;
  26. &lt;/footer&gt;
  27. &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:

确定