After webpack packaging, the vue mount root node element disappears.

when I built my own webpack to package the vue, and introduced the packaged vue, the mount element disappeared

the main reason for setting up your own webpack packaging environment is to learn vue

related codes

1. This is the entry file

import Vue from "vue"
import Child from "./app"
new Vue({
    el: "-sharpapp",
    data: {
        msg: "this is msg"
    },
    render: (h) => h(Child)
})

2. This is the content of the app file introduced by import

import Vue from "vue";

var Child = Vue.component("Child", {
    template: `<div><span>hello world</span></div>>`
});
export default Child;

3. This is the index.html file

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<div id="app">
    {{msg}}
</div>
<script src="./dist/main.js"></script>
</body>
</html>

4. This is the webpack configuration file,

module.exports = {
    entry: {main: "./1.js"},
    output: {
        path: __dirname + "/dist",
        filename: "[name].js"
    },
    module: {
        rules: [
            {
                test: "/\.js$/",
                exclude: "/node_modules/",
                loader: "babel-loader"
            }
        ]
    },
    resolve: {
        alias: {
            "vue":"vue/dist/vue.common.js"
        }
    }
}

the following is the browser element node

<html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title></head>
<body>
<div><span>hello world</span></div>
<script src="./dist/main.js"></script>
</body>
</html>

the root node of index.html, sharpapp, is missing. I don"t know why?

Apr.07,2021

document link

The elements provided by
can only be used as mount points. Unlike Vue 1.x, all mount elements are replaced by DOM generated by Vue . Therefore, it is not recommended to mount root instances to < html > or < body >.

official documentation states that after the vue 2 version, the el node itself is replaced by the html template generated by the components in js, rather than by append.

https://cn.vuejs.org/v2/api/-sharpel


Please read the official document ide/installation.html-sharp%E5%AF%B9%E4%B8%8D%E5%90%8C%E6%9E%84%E5%BB%BA%E7%89%88%E6%9C%AC%E7%9A%84%E8%A7%A3%E9%87%8A" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide. carefully.
the vue you package now is a runtime version and does not include a compiler. Just change the packaged version of vue to the version that includes the compiler. The specific configuration is as follows

clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e67142-45bf0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e67142-45bf0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?