登录

  • 登录
  • 忘记密码?点击找回

注册

  • 获取手机验证码 60
  • 注册

找回密码

  • 获取手机验证码60
  • 找回
毕业论文网 > 外文翻译 > 计算机类 > 计算机科学与技术 > 正文

Vue.js 是什么外文翻译资料

 2022-08-27 10:08  

Introduction

What is Vue.js?

Vue (pronounced /vjuː/, like view) is a progressive framework for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable. The core library is focused on the view layer only, and is easy to pick up and integrate with other libraries or existing projects. On the other hand, Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries.

If yoursquo;d like to learn more about Vue before diving in, we created a video walking through the core principles and a sample project.

If you are an experienced frontend developer and want to know how Vue compares to other libraries/frameworks, check out the Comparison with Other Frameworks.

Watch a free video course on Vue Mastery

Getting Started

Installation

The official guide assumes intermediate level knowledge of HTML, CSS, and JavaScript. If you are totally new to frontend development, it might not be the best idea to jump right into a framework as your first step - grasp the basics then come back! Prior experience with other frameworks helps, but is not required.

The easiest way to try out Vue.js is using the Hello World example. Feel free to open it in another tab and follow along as we go through some basic examples. Or, you can create an index.html file and include Vue with:

lt;!-- development version, includes helpful console warnings --gt;

lt;script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'gt;lt;/scriptgt;

or:

lt;!-- production version, optimized for size and speed --gt;

lt;script src='https://cdn.jsdelivr.net/npm/vue@2'gt;lt;/scriptgt;

The Installation page provides more options of installing Vue. Note: We do not recommend that beginners start with vue-cli, especially if you are not yet familiar with Node.js-based build tools.

If you prefer something more interactive, you can also check out this tutorial series on Scrimba, which gives you a mix of screencast and code playground that you can pause and play around with anytime.

Declarative Rendering

Try this lesson on Scrimba

At the core of Vue.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:

lt;div id='app'gt;

{{ message }}

lt;/divgt;

var app = new Vue({

el: #app,

data: {

message: Hello Vue!

}

})

We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now reactive. How do we know? Open your browserrsquo;s JavaScript console (right now, on this page) and set app.message to a different value. You should see the rendered example above update accordingly.

Note that we no longer have to interact with the HTML directly. A Vue app attaches itself to a single DOM element (#app in our case) then fully controls it. The HTML is our entry point, but everything else happens within the newly created Vue instance.

In addition to text interpolation, we can also bind element attributes like this:

lt;div id='app-2'gt;

lt;span v-bind:title='message'gt;

Hover your mouse over me for a few seconds

to see my dynamically bound title!

lt;/spangt;

lt;/divgt;

var app2 = new Vue({

el: #app-2,

data: {

message: You loaded this page on new Date().toLocaleString()

}

})

Here we are encountering something new. The v-bind attribute you are seeing is called a directive. Directives are prefixed with v- to indicate that they are special attributes provided by Vue, and as you may have guessed, they apply special reactive behavior to the rendered DOM. Here, it is basically saying “keep this elementrsquo;s title attribute up-to-date with the message property on the Vue instance.”

If you open up your JavaScript console again and enter app2.message = some new message, yoursquo;ll once again see that the bound HTML - in this case the title attribute - has been updated.

Conditionals and Loops

Try this lesson on Scrimba

Itrsquo;s easy to toggle the presence of an element, too:

lt;div id='app-3'gt;

lt;span v-if='seen'gt;Now you see melt;/spangt;

lt;/divgt;

var app3 = new Vue({

el: #app-3,

data: {

seen: true

}

})

Go ahead and enter app3.seen = false in the console. You should see the message disappear.

This example demonstrates that we can bind data to not only text and attributes, but also the structure of the DOM. Moreover, Vue

剩余内容已隐藏,支付完成后下载完整资料


Vue.js 是什么

Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用。Vue 的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合。另一方面,当与现代化的工具链以及各种支持类库结合使用时,Vue 也完全能够为复杂的单页应用提供驱动。

如果你想在深入学习 Vue 之前对它有更多了解,我们制作了一个视频,带您了解其核心概念和一个示例工程。

如果你已经是有经验的前端开发者,想知道 Vue 与其它库/框架有哪些区别,请查看对比其它框架

起步

官方指南假设你已了解关于 HTML、CSS 和 JavaScript 的中级知识。如果你刚开始学习前端开发,将框架作为你的第一步可能不是最好的主意——掌握好基础知识再来吧!之前有其它框架的使用经验会有帮助,但这不是必需的。

尝试 Vue.js 最简单的方法是使用 Hello World 例子。你可以在浏览器新标签页中打开它,跟着例子学习一些基础用法。或者你也可以创建一个 .html 文件,然后通过如下方式引入 Vue:

lt;!-- 开发环境版本,包含了有帮助的命令行警告 --gt;

lt;script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'gt;lt;/scriptgt;

或者:

lt;!-- 生产环境版本,优化了尺寸和速度 --gt;

lt;script src='https://cdn.jsdelivr.net/npm/vue'gt;lt;/scriptgt;

安装教程给出了更多安装 Vue 的方式。请注意我们不推荐新手直接使用 vue-cli,尤其是在你还不熟悉基于 Node.js 的构建工具时。

如果你喜欢交互式的东西,你也可以查阅这个 Scrimba 上的系列教程,它揉合了录屏和代码试验田,并允许你随时暂停和播放。

声明式渲染

Vue.js 的核心是一个允许采用简洁的模板语法来声明式地将数据渲染进 DOM 的系统:

lt;div id='app'gt;

{{ message }}

lt;/divgt;

var app = new Vue({

el: #app,

data: {

message: Hello Vue!

}

})

我们已经成功创建了第一个 Vue 应用!看起来这跟渲染一个字符串模板非常类似,但是 Vue 在背后做了大量工作。现在数据和 DOM 已经被建立了关联,所有东西都是响应式的。我们要怎么确认呢?打开你的浏览器的 JavaScript 控制台 (就在这个页面打开),并修改 app.message 的值,你将看到上例相应地更新。

注意我们不再和 HTML 直接交互了。一个 Vue 应用会将其挂载到一个 DOM 元素上 (对于这个例子是 #app) 然后对其进行完全控制。那个 HTML 是我们的入口,但其余都会发生在新创建的 Vue 实例内部。

除了文本插值,我们还可以像这样来绑定元素 attribute:

lt;div id='app-2'gt;

lt;span v-bind:title='message'gt;

鼠标悬停几秒钟查看此处动态绑定的提示信息!

lt;/spangt;

lt;/divgt;

var app2 = new Vue({

el: #app-2,

data: {

message: 页面加载于 new Date().toLocaleString()

}

})

这里我们遇到了一点新东西。你看到的 v-bind attribute 被称为指令。指令带有前缀 v-,以表示它们是 Vue 提供的特殊 attribute。可能你已经猜到了,它们会在渲染的 DOM 上应用特殊的响应式行为。在这里,该指令的意思是:“将这个元素节点的 title attribute 和 Vue 实例的 message property 保持一致”。

如果你再次打开浏览器的 JavaScript 控制台,输入 app2.message = 新消息,就会再一次看到这个绑定了 title attribute 的 HTML 已经进行了更新。

条件与循环

控制切换一个元素是否显示也相当简单:

lt;div id='app-3'gt;

lt;p v-if='seen'gt;现在你看到我了lt;/pgt;

lt;/divgt;

var app3 = new Vue({

el: #app-3,

data: {

seen: true

}

})

继续在控制台输入 app3.seen = false,你会发现之前显示的消息消失了。

这个例子演示了我们不仅可以把数据绑定到 DOM 文本或 attribute,还可以绑定到 DOM 结构。此外,Vue 也提供一个强大的过渡效果系统,可以在 Vue 插入/更新/移除元素时自动应用过渡效果

还有其它很多指令,每个都有特殊的功能。例如,v-for 指令可以绑定数组的数据来渲染一个项目列表:

lt;div id='app-4'gt;

lt;olgt;

lt;li v-for='todo in todos'gt;

{{ todo.text }}

lt;/ligt;

lt;/olgt;

lt;/divgt;

var app4 = new Vue({

el: #app-4,

data: {

todos: [

{ text: 学习 JavaScript },

{ text: 学习 Vue },

{ text: 整个牛项目 }

]

}

})

在控制台里,输入 app4.todos.push({ text: 新项目 }),你会发现列表最后添加了一个新项目。

处理用户输入

为了让用户和你的应用进行交互,我们可以用 v-on 指令添加一个事件监听器,通过它调用在 Vue 实例中定义的方法:

lt;div id='app-5'gt;

lt;pgt;{{ message }}lt;/pgt;

lt;button v-on:click='reverseMessage'gt;反转消息lt;/buttongt;

lt;/divgt;

var app5 = new Vue({

el: #app-5,

data: {

message: Hello Vue.js!

},

methods: {

reverseMessage: function () {

this.message = this.message.split().reverse().join()

}

}

})

注意在 reverseMessage 方法中,我们更新了应用的状态,但没有触碰 DOM——所有的 DOM 操作都由 Vue 来处理,你编写的代码只需要关注逻辑层面即可。

Vue 还提供了 v-model 指令,它能轻松实现表单输入和应用状态之间的双向绑定。

lt;div id='app-6'gt;

lt;pgt;{{ message }}lt;/pgt;

lt;input v-model='message'gt;

lt;/divgt;

var app6 = new Vue({

el: #app-6,

data: {

message: Hello Vue!

}

})

组件化应用构建

组件系统是 Vue 的另一个重要概念,因为它是一种抽象,允许我们使用小型、独立和通常可复用的组件构建大型应用。仔细想想,几乎任意类型的应用界面都可以抽象为一个组件树:

在 Vue 里,一个组件本质上是一个拥有预定义选项的一个 Vue 实例。在 Vue 中注册组件很简单:

// 定义名为 todo-item 的新组件

Vue.component(todo-item, {

template: lt;ligt;这是个待办项lt;/ligt;

})

var app = new Vue(...)

现在你可以用它构建另一个组件模板:

lt;olgt;

lt;!-- 创建一个 todo-item 组件的实例 --gt;

lt;todo-itemgt;lt;/todo-itemgt;

lt;/olgt;

但是这样会为每个待办项渲染同样的文本,这看起来并不炫酷。我们应该能从父作用域将数据传到子组件才对。让我们来修改一下组件的定义,使之能够接受一个 prop

Vue.component(todo-item, {

// todo-item 组件现在接受一个

// 'prop',类似于一个自定义 attribute。

// 这个 prop 名为 todo。

props: [todo],

template: lt;ligt;{{ todo.text }}lt;/ligt;

})

现在,我们可以使用 v-bind 指令将待办项传到循环输出的每个组件中:

lt;div id='app-7'gt;

lt;olgt;

lt;!--

现在我们为每个 todo-item 提供 todo 对象

todo 对象是变量,即其内容可以是动态的。

我们也需要为每个组件提供一个“key”,稍后再

作详细解释。

--gt;

lt;todo-item

v-for='item in grocery

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[405909],资料为PDF文档或Word文档,PDF文档可免费转换为Word

您需要先支付 30元 才能查看全部内容!立即支付

企业微信

Copyright © 2010-2022 毕业论文网 站点地图