How to use ant design vue in html.
I tried to get this library with npm and got access to these files antd.js, antd-with-locales.js.map, antd.js.map, antd-with-locales.min.js, antd. min.js, antd-with-locales.min.js.LICENSE.txt, antd.min.js.LICENSE.txt, antd-with-locales.min.js.map, antd.min.js.map, reset. css, antd-with-locales.js. I tried to enter them into the code with the script tag, but I get an error in the console. This is my code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/reset.css">
<script src="https://unpkg.com/[email protected]/dist/vue.global.js"></script>
<script src="https://unpkg.com/dayjs/dayjs.min.js"></script>
<script src="https://unpkg.com/dayjs/plugin/customParseFormat.js"></script>
<script src="https://unpkg.com/dayjs/plugin/weekday.js"></script>
<script src="https://unpkg.com/dayjs/plugin/localeData.js"></script>
<script src="https://unpkg.com/dayjs/plugin/weekOfYear.js"></script>
<script src="https://unpkg.com/dayjs/plugin/weekYear.js"></script>
<script src="https://unpkg.com/dayjs/plugin/advancedFormat.js"></script>
<script src="https://unpkg.com/dayjs/plugin/quarterOfYear.js"></script>
<title>My first ant design vue page</title>
</head>
<body>
<template>
<a-button>Add</a-button>
</template>
<script src="https://unpkg.com/[email protected]/dist/antd.min.js"></script>
<script>
import { Button } from 'ant-design-vue';
const ButtonGroup = Button.Group;
export default {
components: {
AButton: Button,
AButtonGroup: ButtonGroup,
},
};
</script>
</body>
</html>
And this is my error:
Uncaught SyntaxError: Cannot use import statement outside a module (at first.html:24:9)
You are trying to use it as Single File Component (*.vue), which requires a build step, which makes files usable for the browser.
If you want to use the library directly in the browser, you need to use the global
antd
variable.Instead of manually including components, you can just extract all of them from the
antd
variable. And you probably want to register them globally, so they are available in your custom components, without explicitly including them individually.For serious work with Vue (and Ant Design), you should look into how to use *.vue files with vite.