vue脚手架vue数据交互

Vue.js is a JavaScript library for building user interfaces. Last year, it started to become quite popular among web developers. It’s lightweight, relatively easy to learn, and powerful.

Vue.js是用于构建用户界面JavaScript库。 去年,它开始在Web开发人员中变得非常流行。 它轻巧,易于学习且功能强大。

In the three minutes that Medium says it will take you to read this article, you’ll be equipped to start building basic Vue apps. With each segment, I’ve also included an interactive Scrimba screencast, where you can watch me explain the concepts and play around with the code yourself.

在Medium说的三分钟内,您将需要阅读本文,您将具备开始构建基本的Vue应用程序的能力。 在每个部分中,我还包括一个互动式Scrimba截屏,您可以在其中观看我讲解概念并亲自使用代码。

Let’s jump into it.

让我们跳进去。

模板语法和数据 (Template syntax and data)

At the core of Vue.js is a straightforward template syntax which looks like this:

Vue.js的核心是简单的模板语法,如下所示:

<div id="myApp">  {{ message }}
</div>

Pair that with the following JavaScript snippet:

将其与以下JavaScript代码段配对:

var myApp = new Vue({  el: '#myApp',  data: {  message: 'Hello world!'  }
})

And it’ll result in Hello world! being rendered on the page.

它将进入Hello World! 在页面上呈现。

The el: #myApp part tells Vue to render the app inside the DOM element with the id of myApp. The data object is where you place you the data you want to use in your app. We’ve added only one key here, message, which we’re referencing to in our HTML like this: {{ message }}.

el: #myApp部分告诉Vue使用myApp的ID在DOM元素内渲染应用程序 data对象是放置要在应用程序中使用的数据的位置。 我们在此处仅添加了一个键message ,它在我们HTML中是这样引用的: {{ message }}

Vue takes care of linking the data object to the DOM, so if the data changes, the page will be updated as well.

Vue负责将data对象链接到DOM,因此,如果数据发生更改,页面也将被更新。

This is called declarative rendering. You simply specify what you want to update, and Vue takes care of how to do it.

这称为声明式渲染。 您只需指定要更新什么 ,Vue公司需要照顾怎么办呢。

You can change the data can by doing this:

您可以通过执行以下操作来更改数据罐:

myApp.message = 'Some new value';

Here is a screencast which explains this exact concept:

这是一个截屏视频,解释了这个确切的概念:

指令 (Directives)

The next concept you’ll need to learn is directives. Directives are HTML attributes that are prefixed with v-, which indicates that they apply reactive behavior to the rendered DOM.

您需要学习的下一个概念是指令。 指令是带有v-前缀HTML属性,指示它们将React式行为应用于呈现的DOM。

Let’s say we only want to render something if a condition is true, and hide it if it’s false. Then we’ll use v-if.

假设我们只想在条件为true时渲染某些内容,而在条件为false时隐藏它。 然后,我们将使用v-if

In the HTML, it looks like this.

在HTML中,它看起来像这样。

<div id="app">  <p v-if="seen">Now you see me</p>
</div>

And some JavaScript:

还有一些JavaScript:

var app = new Vue({  el: '#app',  data: {  seen: true  }
})

This will result in rendering out the Now you see me paragraph if seen in data is true. To hide the paragraph, you can set seen to false, like this:

如果在data seen的是真实的,这将导致呈现“ 立即看到我”段落 要隐藏该段落,可以将seen设置为false,如下所示:

app.seen = false;

app.seen = false;

Here is a screencast explaining the same concept:

这是解释相同概念的截屏视频:

There are many other directives, like v-for, v-on, v-bind and v-model.

还有许多其他指令,例如v-forv-on, v-bindv-model

处理用户输入 (Handling user input)

Another core directive you need to learn is v-on. It will hook up an event listener to the DOM element, so that you can handle user input. You specify the type of event after the colon. So v-on:click will listen for clicks.

您需要学习的另一个核心指令是v-on 。 它将事件监听器连接到DOM元素,以便您可以处理用户输入。 您可以在冒号后面指定事件的类型。 因此, v-on:click将监听点击。

<div id="app">  <button v-on:click="myClickHandler">Click me!</button>
</div>

myClickHandler refers to the key with the same name in the methods object. Needless to say, that’s the object where you place your app’s methods. You can have as many methods as you want.

myClickHandlermethods对象中引用具有相同名称的键。 不用说,这就是放置应用程序方法的对象。 您可以根据需要使用多种方法。

var app = new Vue({  el: '#app',  methods: {  myClickHandler: function () {  console.log('button clicked!');  }  }
})

This will result in button clicked being logged to the console when clicking the button.

这将导致按钮单击单击按钮时被记录到控制台。

Here is a screencast explaining the concept:

这是解释此概念的截屏视频:

绑在一起 (Tying it all together)

Now let’s create an example where we’re using both data and methods, tying together what we’ve learned up until now.

现在,让我们创建一个示例,在此示例中,我们同时使用datamethods ,将到目前为止所学的知识联系在一起。

<div id="app">  <p>{{ message }}</p>  <button v-on:click="changeMessage">Click me!</button>
</div>

And the JavaScript:

和JavaScript:

var app = new Vue({  el: '#app',  data: {  message: 'Start message'  },  methods: {  changeMessage: function () {  this.message = 'The message has changed!'  }  }
})

Initially, it’ll display out Start message on the page, however after the click it’ll display This message has changed instead.

最初,它将在页面上显示开始消息 ,但是单击后将显示此消息已更改

The this  keyword refers to the Vue instance, the one we’ve called app. It is on this instance that our data lives, so we can refer to the message data through this.message.

this关键字引用Vue实例,我们将其称为app 。 正是在这种情况下,我们的数据才得以生存,因此我们可以通过this.message引用message数据。

Check out this screencast explaining the concept.

查看此截屏视频,以解释概念。

And by that, you should know enough Vue.js to get started creating simple apps.

这样一来,您应该了解足够的Vue.js才能开始创建简单的应用程序。

In the next tutorial, you’ll learn how to create Vue components. So be sure to follow this publication if you liked this article.

在下一个教程中,您将学习如何创建Vue组件。 因此,如果您喜欢本文,请确保遵循该出版物。

翻译自: https://www.freecodecamp.org/news/learn-basic-vue-js-crash-course-guide-vue-tutorial-e3da361c635/

vue脚手架vue数据交互

vue脚手架vue数据交互_学习Vue:3分钟的交互式Vue JS教程相关推荐

  1. web数据交互_通过体育运动使用定制的交互式Web应用程序数据科学探索任何数据...

    web数据交互 Most good data projects start with the analyst doing something to get a feel for the data th ...

  2. Vue中的数据交互axios

    数据交互 ajax: 原理必须要能说出来流程即可. jquery_ajax. 我们promise要结合它 Promise + async函数的 前端的主要工作:1. 画页面.2. 请求ajax (后端 ...

  3. vue 高阶面试题_高级Web前端工程师面试之Vue问题汇总解析

    又是一年毕业季,很多学习前端的同学面对激烈的求职竞争倍感压力,想要了解企业招聘会提问哪些问题.今天千锋郑州Web前端培训小编就给大家分享一下高级Web前端工程师面试中有关Vue的问题及解析. 1.Vu ...

  4. vue component created没有触发_面试!面试!面试!vue常见面试题。

    "金三银四"的时候到了,一大批准备跳槽的程序员蠢蠢欲动,小编最近也在投简历,找工作.现在很多公司都要求vue.react.ng三大主流框架中的一两个.小编在此总结一下vue常见的面 ...

  5. dialogfragment 数据交互_交互的学习与应用指南 | 人人都是产品经理

    编辑导语:交互设计就是互联网产品与用户之间的一个交流,交互设计是比较了解和靠近用户体验的,以用户为中心对交互过程进行研究和设计:本文作者分享了关于交互的学习和应用指南,我们一起来了解一下. 千万不要以 ...

  6. 12_心理咨询_微信小程序项目实战_数据交互_深入理解小程序

    前言 我们实现静态页面,只需要稍微懂一点HTML/CSS即可或者零基础都可以,但是如果想要进行数据交互,需要对小程序有一定的理解: 小程序提供了一个简单.高效的应用开发框架和丰富的组件及API,帮助开 ...

  7. 15_心理咨询_微信小程序项目实战_数据交互_首页

    前置 把十方智育的图片资源.视频资源等都放在json-server的public目录下面的指定文件夹中:                 public    json-server的静态资源目录    ...

  8. python后端与前端数据交互_前端与后端的数据交互(jquery ajax+python flask)

    前端与后端的数据交互,最常用的就是GET.POST,比较常用的用法是:提交表单数据到后端,后端返回json 前端的数据发送与接收 1)提交表单数据 2)提交JSON数据 后端的数据接收与响应 1)接收 ...

  9. vue和Java做数据交互_基于vue和springmvc前后端分离,json类接口调用介绍

    基于vue和springmvc前后端分离,json类接口调用介绍 版本要求:spring-3.2.9.RELEASE.vue-2.9.2.axios-0.17.1,其中axios作为http clie ...

最新文章

  1. 通过loganalyzer展示数据库中的日志
  2. N-LTP:基于预训练模型的中文自然语言处理平台
  3. 下拉菜单实现树状结构_二叉索引树(树状数组)的原理
  4. Gerrit评审报错[remote rejected] develop- refs/for/develop(no new changes)
  5. 基于surging 的stage组件设计,谈谈我眼中的微服务
  6. 通过“FBI树”复习二叉树算法(洛谷P1087题题解,Java语言描述)
  7. 浅谈:飞鸽传书 的TCP/IP原理
  8. 常见的c语言头文件作用,C语言的头文件的作用是什么?
  9. file owner
  10. Effective Receptive Field
  11. 如何覆盖 CRA 默认 webpack 配置
  12. 各行业的英语术语(绝对精华 2)
  13. QQ如何应对中年困境?
  14. 【刷题记录14】Java工程师丨腾讯面试真题(2)
  15. 计算机的文件打开记录怎么删,怎样删除最近使用的文档记录,电脑文档文件怎么删除...
  16. Aria2 ,下载神器
  17. 【Web技术】1374- 纯 JS 实现灵活的前端主题切换功能
  18. 阿里云OSS配置及使用
  19. HDLBits Lemmings3
  20. 高通平台camera客观项测试之解析力均匀性

热门文章

  1. 大话数据结构—栈与队列
  2. System.Configuration命名空间下的关键类
  3. sys.modules[__name__]的一个实例
  4. zookeeper、hbase常见命令
  5. ORACLE1.21 PLSQL 01
  6. eclipse类自动生成注释
  7. Use Selenium webdriver in Javascript
  8. 昨天添加的clustrMaps,忘了截屏,今天补上,就作为我在园子里的奠基。
  9. Hive2.1.1、Hadoop2.7.3 部署
  10. 文件系统管理 之 文件和目录访问权限设置