Development background:
suppose there is a h5 app
project, the front and rear ends are completely separated, the front end communicates data through json
, and the front end uses vue
for data rendering development.
questions / requirements
at present, ui
has completed the interface of the entire project, with 30 +
pages. In front-end development, every html
page inevitably has a common part, which is generally as follows:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="....">
<!-- meta -->
<!-- ...meta... ---->
<link rel="stylesheet" href="public/css/base.css" />
<link rel="stylesheet" href="public/css/module.css" />
<!-- css -->
<!-- ...link... ---->
<script src="plugins/Loading/loading.js"></script>
<script src="public/lib/jquery.js"></script>
<!-- js -->
<!-- ...script... ---->
<!-- --->
<title></title>
</head>
<body>
<!-- -->
<!-- ... -->
<script src="public/js/public.js"></script>
<!-- js -->
<!-- ...script... ---->
</body>
</html>
how to separate the public parts, such as < head >. < / head >
, which are loaded on each page, by the way of vue
, and then load these public parts on each page? The solution is to avoid page-by-page changes if you need to add some code to the common parts of all pages.
above I may not have clearly stated my needs, comparing to the blade
templates of some PHP Laravel
frameworks:
define a top-level page ( top.blade.php
), define an application-level generic page ( public.blade.php
), and define a specific page based on each controller / method ( index.blade.php
).
inheritance: index.blade.php
inherit public.blade.php
, public.blade.php
inherit top.blade.php
.
in this way, if you add new files to the public part, you can easily achieve the need to add the public part to all pages simply by adding new content in public.blade.php or top.blade.php
!
in fact, I intend to achieve a function similar to the back-end template engine in the case of a pure front-end! May I ask how to achieve it?