I was wondering if it was possible to build a vuejs component that could be embedded into another site. The thing is the component would show up several times on the website so I wouldn't have access to a root element. I know a way to do this in react but I'd rather do it in Vue.
相关问题
- Axios OPTIONS instead of POST Request. Express Res
- 反爬能检测到JS模拟的键盘输入吗
- 有没有方法即使程序最小化也能对其发送按键
- Vue.js - set slot content programmatically
- Getting Uncaught TypeError: …default is not a cons
I know,i am not answering your question as you want (using vue component in another site).
By clicking here you see an awesome tutorial about it.
Yes, it is possible.
I created this project a long time ago https://github.com/lmarqs/odw-form. The objective was to create embeddable components to be into other sites.
It was created using vue-cli but I had to adapt it.
Basically, I created a new entry file to the webpack (main.prod.js). This entry installs the components on Vue. So in the html is is possible to create somenthing like this:
After creating the new entry I setted the entry on webpack.base.conf.js
Then, running the
npm run build
command the embeddable css and js files are created into/dist
folder.You can put more than one root elements in one site. Every component needs to be rendered under a root. Furthermore you always have access to the root via the
$root
property. What is your question?