zoukankan      html  css  js  c++  java
  • Vue3.0到底带来来哪些变化视频笔记1

    创建项目目录

    mkdir vue-next-sample

    初始化package.json文件 

    npm init --yes

    安装Vue3.0模块

    npm i vue@next

    安装Webpack相关模块

    npm i webpack webpack-cli webpack-dev-server --save-dev

    安装一些需要用到的Webpack插件

    npm i html-webpack-plugin mini-css-extract-plugin --save-dev

    安装Vue.js单文件组件的loader

    npm i vue-loader@next @vue/compiler-sfc --save-dev

    安装 css-loade

     npm i css-loader --save-dev

    建立项目文件结构

    src  源文件目录

    public html文件目录

      

    在src目录建立Vue组件

    App.vue

    内代码

    与Vue2.0的区别,可以定义多个div,Vue2.0只能挂载一个div

    <template>
      <div>Hello {{ title }}</div>
      <div>{{ count }}</div>
      <div><button value="+" @click="increment">+</button></div>  
    </template>
    
    <script>
      //导入自定义组件和ref包裹器   
      import  { defineComponent,ref } from 'vue'
      export default defineComponent({
        setup () {
    
          const count=ref(1)
    
          const increment=()=>count.value++
    
    
          return {
            title:'vue.3.011111',
            count,
            increment
          }
        }
      })
    </script>
    
    <style>
    div {
      color:blue;
    }
    </style>
    

    建立入口主文件

    main.js

    import { createApp } from 'vue'
    import App from './App.vue'
    
    //创建应用对象
    const app=createApp(App)
    //挂载到html的节点,ID为root的div节点
    app.mount('#root')
    

      

    建立webpack打包配置文件

    webpack.config.js

    // module.exports={
    
    // }
    const path=require('path')
    const webpack=require('webpack')
    const HtmlWebpackPlugin=require('html-webpack-plugin')
    const MiniCssExtractPlugin=require('mini-css-extract-plugin')
    const { VueLoaderPlugin } = require('vue-loader')
    
    
    //引入,未来写代码有智能提示,采用的es6规范的写法
    // import  webpack from 'webpack'
    
    /** 
    *@type {webpack.Configuration}
    */
    const config={
      entry:'./src/main.js',
      output:{
        filename:'bundle.js',
        path:path.join(__dirname,'dist')
      },
      module:{
        rules:[
          {
            test:/.vue$/,
            use:'vue-loader'
          },
          {
            test:/.css$/,
            use:[MiniCssExtractPlugin.loader,'css-loader']
          }
        ]
      },
      plugins:[
        new HtmlWebpackPlugin({
          template:'./public/index.html'
        }),
        new MiniCssExtractPlugin(),
        new VueLoaderPlugin(),  
        new webpack.HotModuleReplacementPlugin() //热更新插件
      ]
    } 
    
    module.exports=config
    

      

    public文件夹建立index.html用于挂载组件的html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <div id="root"></div>
    </body>
    </html>
    

      webpack打包

    npx webpack

    webpack热更新

    npx webpack-dev-server --hot

    Vue3.0的优势

    没有this

    更好的类型推导能力

    更待的代码压缩空间

    更友好的Tree Shaking支持

    更灵活的逻辑复用能力

  • 相关阅读:
    mysql练习
    导航 开发 常用 官方网址 办公 政府 网站 url
    Yii 数据库 连接 Error Info: 向一个无法连接的网络尝试了一个套接字操作。
    xampp Apache Access forbidden! Error 403 解决方法
    MySQL 没有密码 初始化 设置 用户名
    Apache 虚拟机 vhosts C:WINDOWSsystem32driversetchosts
    js 返回上一页 链接 按钮
    MySQL concat concat_ws group_concat 函数(连接字符串)
    PHP的UTF-8中文转拼音处理类(性能已优化至极致)
    原生JavaScript实现金额大写转换函数
  • 原文地址:https://www.cnblogs.com/CelonY/p/12513365.html
Copyright © 2011-2022 走看看