1.新建a.html(public文件夹下)文件,并设定div的id=“a”
<!DOCTYPE html> <html lang=""> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <link rel="icon" href="<%= BASE_URL %>favicon.ico"> <title><%= htmlWebpackPlugin.options.title %></title> </head> <body> <noscript> <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> </noscript> <div id="a"></div> </body> </html>
2.新建a.vue文件,注意文件的路径,本案例在src文件夹下
<template> <div id="a"> {{name}} </div> </template> <script> export default { data() { return { name:jack, }; }, name: "A", components: { //HelloWorld }, }; </script> <style> </style>
3.新建a.js文件(src文件夹下)
import Vue from 'vue'
import Backstage from './a.vue'
new Vue({
render: h => h(A),
}).$mount('#a')
4.新建vue.config.js文件(很关键,这个文件可以让vue能找到上述自定义的文件)
module.exports = {
pages: {
mould: {
entry: 'src/a.js', //配置入口js文件
template: 'public/a.html', //主页面
filename: 'a.html', //打包后HTML文件名称
title: '测试自定文件' //打包后。HTML文件标题
}
}
}