Vue基础入门学习

vue安装

下载地址

https://cn.vuejs.org/v2/guide/installation.html

版本选择

选择开发版本下载

 

 

如何引入

直接用 <script> 引入,直接下载并用 <script> 标签引入,Vue 会被注册一个全局变量

<script src="js/vue.js"></script>

Vue入门程序

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml"head>
    Meta charset="UTF-8"title>Vue入门程序 </script src="js/vue.js"></scriptbody>
  <!--div标签就是挂载点,挂载点内部都是模板内容-->
  div id="root">
      v-on:click和@click效果一样,为简写形式-->
      @click="welcome">{{msg}}div使用v-text直接输出转义后文本v-text="content"显示未转义文本v-html>
      var root;
      // vue实例
      root=new Vue({
          el:"#root,模拟内容
           template:'<h1>helllow {{msg}}</h1>',
          data:{
              msg: world<h1>111111</h1>
          },1)">methods中定义事件及函数方法
          methods:{
              welcome:function () {
                  this.msghellow world!
              }
          }
      })
  >

html>

Vue中的属性绑定和双向数据绑定

="http://www.w3.org/1999/xhtml" xmlns:v-bind>Vue中的属性绑定和双向数据绑定使用v-bind做属性绑定,其中title是vue实例中的变量对象
      可简写为:title即:冒号+属性名称,:+title :title="'hey '+title"> hellow world !input v-model/>
      >{{content}}属性绑定语法:使用:+属性名称双向数据绑定语法:使用v-model="vue中的变量对象名称"hellow world !this is content!
          }
      })
  >

小结

使用v-bind做属性绑定,其中title是vue实例中的变量对象

可简写为:title即:冒号+属性名称,如::+title 

属性绑定语法:使用:+属性名称

双向数据绑定语法:使用v-model="vue中的变量对象名称"

Vue中的计算属性和侦听器

>Vue中的计算属性和侦听器>="firstName"/>="lastName">{{fullName}}>{{count}}
      侦听器值得是监听某个数据的变化,一旦变化就可以在监听方法了,做业务逻辑
      计算属性computed,指的是他是有其他属性经过运算而来,即新的结果
   root;
      rootirstName:""0mputed:{
              fullName:return .firstName+" .lastName
              }
          },watch:{
              fullName:.count++;
              }
          }
      })
  >

侦听器值得是监听某个数据的变化,一旦变化就可以在监听方法了,做业务逻辑

计算属性computed,指的是他是有其他属性经过运算而来,即新的结果

v-if,v-show与v-for指令


      xmlns:key>v-if,v-show与v-for指令v-if="show"button ="isdisplay">my buttonbuttonul>
          li v-for="(item,index) of list" :key="index">{{item}}li="item of list" app;
      123],show:truedisplay:.show=!.show;
              }
          }
      })
  >

v-if

有移除元素标签效果,控制dom的存在与否

v-show

控制dom的显示与否,元素显示或隐藏

v-for

控制一组数据,控制一组数据,通过控制一组数据来循环显示一组数据的dom结构

todolist功能开发

>todolist功能开发="inputValue"="submit">提交 app;
      app''使用push为数据赋值
                  .list.push(.inputValue);
                  .inputValue>

todolist组件拆分

>todolist组件拆分todo-item ="index" :content="item"todo-item 全局组件
      Vue.component(todo-itemcontent<li>{{content}}</li>
          }
      )
      局部组件的使用
       var Todoitem={
           template:"<li>item</li>"
       }
       components:{
               "todo-item":Todoitem
           },1)">          data:{
              inputValue:>

todolist的删除功能

>实现todolist的删除功能/>
    >
        ="item" :index
                   @delete="ieDelete">
        Vue.component('index接收显示内容和下标
            template: <li @click='isclick'>{{content}}</li> () {
                    触发删除事件
                    .$emit(delete.index)
                }
            }
        }
    )
    局部组件的使用
     var Todoitem={
         template:"<li>item</li>"
     }
     app;
    app =  Vue({
        el:  components:{
             "todo-item":Todoitem
                data: {
            inputValue:  () {
                使用push为数据赋值
                .inputValue);
                .inputValue 
            },ieDelete:  (index) {
                从对应下标中删除一项
                .list.splice(index,1)">)
            }
        }
    })
>

 

C:\Users\ASUS>cnpm install --global vue-cli
Downloading vue-cli to E:\Program Files\nodejs\node_modules\vue-cli_tmp
copying E:\Program Files\nodejs\node_modules\vue-cli_tmp\_vue-cli@2.9.6@vue-cli to E:\Program vue-cli
Installing vue-cli's dependencies to E:\Program Files\nodejs\node_modules\vue-cli/node_modules
[1/20] commander@^2.9.0 installed at node_modules\_commander@2.20.3@commander
[2/20] multimatch@^2.1.0 installed at node_modules\_multimatch@2.1.0@multimatch
[3/20] ora@^1.3.0 installed at node_modules\_ora@1.4.0@ora
[4/20] consolidate@^0.14.0 installed at node_modules\_consolidate@0.14.5@consolidate
[5/20] rimraf@^2.5.0 existed at node_modules\_rimraf@2.7.1@rimraf
[6/20] minimatch@^3.0.0 installed at node_modules\_minimatch@3.0.4@minimatch
[7/20] async@^2.4.0 installed at node_modules\_async@2.6.3@async
[8/20] semver@^5.1.0 installed at node_modules\_semver@5.7.1@semver
[9/20] tildify@^1.2.0 installed at node_modules\_tildify@1.2.0@tildify
[10/20] uid@0.0.2 installed at node_modules\_uid@0.0.2@uid
[11/20] user-home@^2.0.0 installed at node_modules\_user-home@2.0.0@user-home
[12/20] read-Metadata@^1.0.0 installed at node_modules\_read-Metadata@1.0.0@read-Metadata
[13/20] chalk@^2.1.0 installed at node_modules\_chalk@2.4.2@chalk
[14/20] validate-npm-package-name@^3.0.0 installed at node_modules\_validate-npm-package-name@3.0.0@validate-npm-package-name
[15/20] coffee-script@1.12.7 existed at node_modules\_coffee-script@1.12.7@coffee-script
[16/20] inquirer@^6.0.0 installed at node_modules\_inquirer@6.5.2@inquirer
[17/20] Metalsmith@^2.1.0 installed at node_modules\_Metalsmith@2.3.0@Metalsmith
[18/20] download-git-repo@^1.0.1 installed at node_modules\_download-git-repo@1.1.0@download-git-repo
[19/20] handlebars@^4.0.5 installed at node_modules\_handlebars@4.5.3@handlebars
[20/20] request@^2.67.0 installed at node_modules\_request@2.88.0@request
deprecate Metalsmith@2.3.0 › gray-matter@2.1.1 › coffee-script@^1.12.4 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
All packages installed (239 packages installed from npm registry,used 13s(network 13s),speed 407.65kB/s,json 223(445.52kB),tarball 4.55MB)
[vue-cli@2.9.6] link E:\Program Files\nodejs\vue@ -> E:\Program Files\nodejs\node_modules\vue-cli\bin\vue
[vue-cli@2.9.6] link E:\Program Files\nodejs\vue-init@ -> E:\Program vue-init
[vue-cli@2.9.6] link E:\Program Files\nodejs\vue-list@ -> E:\Program vue-list

C:\Users\ASUS>@minimatch
[7/20] chalk@^2.1.0 installed at node_modules\_chalk@2.4.2@chalk
[8/20] semver@^5.1.0 installed at node_modules\_semver@5.7.1@semver
[9/20] async@^2.4.0 installed at node_modules\_async@2.6.3@async
[10/20] uid@0.0.2 installed at node_modules\_uid@0.0.2@uid
[11/20] coffee-script@1.12.7 existed at node_modules\_coffee-script@1.12.7@coffee-script
[12/20] read-Metadata@^1.0.0 installed at node_modules\_read-Metadata@1.0.0@read-Metadata
[13/20] tildify@^1.2.0 installed at node_modules\_tildify@1.2.0@tildify
[14/20] user-home@^2.0.0 installed at node_modules\_user-home@2.0.0@user-home
[15/20] Metalsmith@^2.1.0 installed at node_modules\_Metalsmith@2.3.0@Metalsmith
[16/20] validate-npm-package-name@^3.0.0 installed at node_modules\_validate-npm-package-name@3.0.0@validate-npm-package-name
[17/20] download-git-repo@^1.0.1 installed at node_modules\_download-git-repo@1.1.0@download-git-repo
[18/20] request@^2.67.0 installed at node_modules\_request@2.88.0@request
[19/20] inquirer@^6.0.0 installed at node_modules\_inquirer@6.5.2@inquirer
[20/20] handlebars@^4.0.5 installed at node_modules\_handlebars@4.5.3@handlebars
deprecate Metalsmith@2.3.0 › gray-matter@2.1.1 › coffee-script@^1.12.4 CoffeeScript 
C:\Users\ASUS>vue init webpack my-project

C:\Users\ASUS>"E:\Program Files\nodejs\\node.exe"  "E:\Program Files\nodejs\\node_modules\vue-cli\bin\vue" init webpack my-project

'git' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
? Project name my-project
? Project description A Vue.js project
? Author rongrong
? Vue build standalone
? Install vue-router? No
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recommended) npm

   vue-cli · Generated "my-project".


# Installing project dependencies ...
# ========================

npm WARN deprecated extract-text-webpack-plugin@3.0.2: Deprecated. Please use https://github.com/webpack-contrib/mini-css-extract-plugin
npm WARN deprecated browserslist@2.11.3: browserslist 2 Could fail on reading browserslist >3.0 config used in other tools.
npm WARN deprecated bfj-node4@5.3.1: Switch to the `bfj` package for fixes and new features!
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please,upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated browserslist@1.7.7: browserslist 2 Could fail 
npm WARN deprecated circular-json@0.3.3: Circularjson is in maintenance only,flatted is its successor.

> core-js@2.6.11 postinstall C:\Users\syp831\my-project\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js )  polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also,the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> ejs@2.7.4 postinstall C:\Users\syp831\my-project\node_modules\ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)


> uglifyjs-webpack-plugin@0.4.6 postinstall C:\Users\ASUS\my-project\node_modules\webpack\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 1322 packages from 707 contributors and audited 12454 packages in 273.689s

23 packages are looking  funding
  run `npm fund`  details

found 13 vulnerabilities (1 low,8 moderate,4 high)
  run `npm audit fix` to fix them,or `npm audit`  details


Running eslint --fix to comply with chosen preset rules...
# ========================


> my-project@1.0.0 lint C:\Users\syp831\my-project
> eslint --ext .js,.vue src "--fix"


# Project initialization finished!
# ========================

To get started:

  cd my-project
  npm run dev

Documentation can be found at https://vuejs-templates.github.io/webpack

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


可以通过min-width属性来设置el-table-column的最小宽度。以下是一个示例: &lt;template&gt; &lt;el-table :data=&quot;tableData&quot;&gt; &lt;el-table-column prop=&quot;item_no&q
yarn dev,当文件变动后,会自动重启。 yanr start不会自动重启 nodemon会监听文件变动,跟yarn dev和yarn start无关。
ref 用于创建一个对值的响应式引用。这个值可以是原始值(如数字或字符串)或对象。当 ref 的值发生变化时,Vue 会自动更新 DOM 或任何其他使用该 ref 的响应式依赖。 使用示例: import { ref } from &#39;vue&#39;; const count = ref(0
通过修改 getWK005 函数来实现这一点。这里的 query 参数就是发送 GET 请求时的查询参数。你可以将需要的条件作为 query 对象的属性传递进去。比如,如果你想要按照特定的条件查询信息,你可以在调用 getWK005 函数时传递这些条件。例如: getWK005({ conditio
&lt;el-form-item label=&quot;入库类型&quot; prop=&quot;mt_type&quot;&gt; &lt;el-select v-model=&quot;form.mt_type&quot; filterable placeholder=&quot;请选择&q
API 变动 样式类名变化: 一些组件的样式类名有所变动,可能需要更新你的自定义样式。 事件名和属性名变化: 某些组件的事件名和属性名发生了变化,需要检查 Element Plus 文档 以了解详细信息。 使用 setup 函数: 在 Vue 3 中,可以使用 Composition API(如 s
安装和引入方式 Element UI (Vue 2): // main.js import Vue from &#39;vue&#39;; import ElementUI from &#39;element-ui&#39;; import &#39;element-ui/lib/theme-cha
排查400 (Bad Request)和解决这个问题,可以按照以下步骤进行: 检查URL和端点:确保URL http://127.0.0.1:8008/basicApp/BS037HModel/ 是正确的,并且该端点在服务器上存在。 检查请求参数:确认发送请求时的任何参数都是正确的,包括查询参数、请
在 Vue.js 中,&lt;template&gt; 标签是一种特殊的标签,它用于定义组件的模板,但不会直接渲染为 HTML 元素。它的主要用途是在编写组件和使用插槽时提供灵活的模板定义。以下是关于 &lt;template&gt; 标签的一些关键概念和使用示例。 基本用法 组件模板:在单文件组件
el-config-provider是Element Plus库中的一个组件,用于提供全局的配置。它是Element Plus在2.0版本中引入的新组件。 el-config-provider组件的作用是允许你在应用程序中统一配置Element Plus的一些全局属性和样式,这些配置将被应用于所有E
onMounted 是一个生命周期钩子函数,在组件挂载到 DOM 后运行。在这里你可以执行需要在组件可用后进行的操作,比如获取数据、设置订阅或初始化第三方库。 使用示例: import { onMounted } from &#39;vue&#39;; onMounted(() =&gt; { //
mt_qty: (this.temp.id &amp;&amp; this.temp.mt_qty) ? this.temp.mt_qty : event.wo_wip,在这个修正后的代码中,使用了条件三元运算符来判断 this.temp.id 是否存在且 mt_qty 是否已被赋值。如果条件成立,
Axios是一个基于Promise的易用、简洁且高效的HTTP请求插件,可以用于浏览器和Node.js。首先执行yarn命令安装依赖,安装成功时在package.json文件的dependencies下多出了Axios及其版本号,笔者写此书时,安装的版本为0.26.1,如所示。 yarn add a
async 关键字用于声明一个异步函数,这个函数会返回一个 Promise 对象。与 await 关键字配合使用时,可以在异步函数中暂停代码执行,直到 Promise 解决或拒绝,从而使异步代码的处理更简单和同步化。 使用 async 的示例 下面是一个完整的 Vue 3 组件示例,展示了如何使用
Promise 是 JavaScript 中用于处理异步操作的一种对象。它代表了一个异步操作的最终完成(或失败)及其结果值。在处理异步操作时,Promise 提供了一种更干净、更可读的方式来管理回调函数。 Promise 的状态 一个 Promise 对象有三种状态: Pending(进行中):初始
在 JavaScript 中,await 是一个用于处理异步操作的关键字。它只能在 async 函数内部使用,并且用于等待一个 Promise 对象的解析。在 Vue 3 中,await 关键字常用于在组合式 API 的 setup 函数中处理异步操作,比如数据获取。 使用 await 的示例 以下
引入样式 Element UI (Vue 2): import &#39;element-ui/lib/theme-chalk/index.css&#39;; Element Plus (Vue 3): import &#39;element-plus/dist/index.css&#39;;
-D和-S区别 安装的环境不同 -D是--save-dev的简写,会安装在开发环境中(production)中的devPendencies中 -S是--save的简写,会安装在生产环境中(development)中的dependencies中
Element-plus的徽章组件el-badge Element Plus 是一个基于 Vue.js 的 UI 组件库,它提供了一系列的常用 UI 组件供开发者使用。其中,徽章组件(el-badge)是其中之一。 徽章组件(el-badge)可以在其他元素上展示一个小圆点或者一个数字,用于标记某种
vscode element-plus/lib/theme-chalk/index.css报错路径找不到 import { createApp } from &#39;vue&#39; import &#39;./style.css&#39; import App from &#39;./App.v