在前端开发全面进入前端的时代 作为一个合格的前端开发工作者 框架是不可或缺的Vue React Anguar 作为前端小白,追随大佬的脚步来到来到博客园,更新现在正在学习的Vue

注 : 相信学习Vue的都已经比较熟练的掌握了Js基础 ES6 jquery 日常代码调试 Node.js 环境 npm使用 不然学Vue可能比较吃力

推荐安装Vue的Chrome拓展程序方便调试代码(在谷歌商店搜索Vue 下载第一个)

vue官网指南 > https://cn.vuejs.org/v2/guide/index.html

vue在线库

 <script src="https://cdn.jsdelivr.net/npm/vue"></script>

Vue -- Hello word

HTML代码:
<div id="app">
{{ message }}
</div> js代码:
var app = new Vue({
el: '#app', //el指定位置 css选择器
data: {
message: 'Hello Vue!' //加载数据 app.message可以直接访问
}
})

看到这一步,可以确认我们打印出了第一行Vue代码,我们要怎么确认呢?打开你的浏览器的 JavaScript 控制台,并修改 app.message 的值,你将看到上例相应地更新

  • 注意!!!!!!! 刚开始会遇到这样的错误 [Vue warn]: Cannot find element

为什么呢 ? 因为: 你的脚本是在目标dom元素被加载到dom之前执行

具体解释: 你已经将你的脚本放置在页面的头部或放置在div元素之前的脚本标记。所以当脚本执行时,它将无法找到目标元素,从而出现错误。

我的解决办法 将引用的Vue库 和main.js 放在代码的最后面

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
</head>
<body>
</body>
<script src="vue.js"></script>
<script src="main.js"></script>
</html>

新手请勿踩坑

接下在就开始Vue学习了

参考 Vue官方文档 书籍:Vue.js实战 个人感觉文档说说的很好 但是细节说的并不多 在博客中也对小细节进行补充

实例与数据

Vue.js 的创建非常简单 ,使用构造函数Vue就可以创建Vue的根实例,并启动Vue实例

var app = new Vue({
el:"#app",
data:{}
//选项
})

变量app代表这个实例

事实上几乎 所有的代码都是一个对象,写入Vue的实例选项内

上面说的太正式了 说简单点 吧,首先说一下 eldata代表什么

  • el : 用于指定一个页面已经存在的DOM (就是 id class) 来挂载Vue实例 可以使用js的DOM原生代码或者CSS选择器
  • data : 可以理解为Vue用到的数据值
var app = new Vue({
el:"#app",//document.getElementById("app") 当然推荐css选择器写法啦
data:{
data:1 //html 的{{ data }} 就是 1
}
//选项
})

Vue特性 双向绑定

Vue.js很有特色的功能 不说太多 贴代码

  <div id="app1">
<input type="text" v-model="my"> //v-model 双向绑定
{{ my }}
</div> js:
new Vue({
el:"#app1",
data:{
my:"欢迎来到Vue"
}
})

在输入框内输入就是左边的input就会实时变化

虽然 v-model虽然很像使用了双向数据绑定的 Angular 的 ng-model但是 Vue 是单项数据流v-model 只是语法糖而已 不过这不影响初学者使用,了解一下

今天就写这么多吧

​ 2018-2-26 23:42

Vue报错 [Vue warn]: Cannot find element的更多相关文章

  1. vue报错[Vue warn]: Unknown custom element: <router-Link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

    vue浏览器报错,如下 vue.runtime.esm.js?2b0e:619 [Vue warn]: Unknown custom element: <router-Link> - di ...

  2. vue报错[Vue warn]: The data property "record" is already declared as a prop. Use prop default value instead.

    当我写了一个子组件,点击打开子组件那个方法时报了一个错 这句话说明意思呢?谷歌翻译一下↓ 数据属性“record”已声明为prop. 请改用prop默认值. 感觉翻译的有点怪,通过最后修改代码后大概意 ...

  3. vue报错 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's

    [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent c ...

  4. Vue 报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders

    场景:父组件向子组件传递数据,子组件去试图改变父组件数据的时候. 解决:子组件通过事件向父组件传递信息,让父组件来完成数据的更改. 比如:我的父组件是普通页面,子组件是弹窗的登录界面,父组件传递的数据 ...

  5. Vue 报错Error in render: “TypeError: Cannot read properties of null (reading ‘xxx’)” found in

    前端vue报错 [Vue warn]: Error in render: "TypeError: Cannot read properties of null (reading 'name' ...

  6. Vue报错 type check failed for prop “xxx“. Expected String with value “xx“,got Number with value ‘xx‘

    vue报错    [Vue warn]: Invalid prop: type check failed for prop "name". Expected String with ...

  7. Vue报错——“Trailing spaces not allowed”

    在VSCode中开发Vue 报错:“Trailing spaces not allowed” 这是空格多了,删除多余的空格就可以了

  8. vue报错Error in render: "TypeError: Cannot read property '0' of undefined"

    通常有两种情况: 1.在模板的html标签上使用length报错 vue 中使用 length判断的时候,有时会报错,如下: <div class="item_list" v ...

  9. vue 报错 :属性undefined(页面成功渲染)

    vue 报错:Cannot read property 'instrumentId' of undefined" 相关代码如下: <template> ... <span& ...

随机推荐

  1. JSP初学者3

    reponse代表服务器对客户端的响应.大部分时候,程序无须使用response来响应客户端请求,因为有更简单的响应对象——out,它代表页面输出流. 但out无法响应生成非字符内容(out是JspW ...

  2. Windows下COCOS2D-X开发环境配置

    1. 下载Android SDK: http://developer.android.com/sdk/index.html ,解压到E:\ADT 目录下 2. 下载NDK: http://develo ...

  3. CompletionService的异常处理

    一.采用take()方法时发生异常 示例代码: 情况一:异常比另一个正确任务,较晚出现,正确任务的结果会打印出 import java.util.concurrent.Callable; import ...

  4. php入门到精通(复习笔记)

    第一章:php语言基础 1,标记风格: ①<?php echo “hello”;?> ②<script language="php">echo " ...

  5. pl/sql 存储过程执行execute immediate 卡住

    在存储过程中,执行了create table.update table.insert into table 但是在使用pl/sql的存储过程调试的时候,一有问题就直接卡住(标识:执行中.....) 后 ...

  6. MSMQ学习笔记一——概述

    一.MSMQ是什么 Message Queuing(MSMQ) 是微软开发的消息中间件,可应用于程序内部或程序之间的异步通信.主要的机制是:消息的发送者把自己想要发送的信息放入一个容器中(我们称之为M ...

  7. 一点一点学写Makefile(6)-遍历当前目录源文件及其子目录下源文件

    时候,我们在开发的时候需要将本次工程的代码分成多个子目录来编写,但是在Makefile的编写上却是个问题,下面我就教大家怎么构建带有子文件夹的源代码目录的自动扫描编译 下面这张图是我的文件树 这里面s ...

  8. Twitter Typeahead plugin Example

    原文网址: http://dhtmlexamples.com/2012/02/27/using-the-typeahead-plugin-with-twitter-bootstrap-2-and-jq ...

  9. LA 4987 背包

    题意: 有n个施工队,给定他们的位置,有m个防空洞,给定位置,求将施工队放到m个防空洞里面,最少的总距离? n<=4000 分析: dp[i][j] 前 i 个施工队,放到前 j 个防空洞里面的 ...

  10. 【luogu P2194 HXY烧情侣】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2194 第一问:缩点并且统计其强连通分量里的最小耗费.把所有强连通分量的最小耗费加起来. 第二问:统计在每个强 ...