vue学习记录②(hello world!)
2020-02-01 11:34
676 查看
接着上篇vue-cli脚手架构建项目结构建好项目之后,就开始写个“hello world!”吧~~~
vue玩的都是组件,所以开发的也是组件。
1.新建helloworld.vue。(删除Hello.vue)代码如下:
<!--模板部分--> <template> <div class="container"> <h1>hello,world!</h1> <p>{{test}}</p> </div> </template> <!--js部分--> <script> export default { name: 'helloworld', data() { return { test: 'this is a test' }; } } </script> <!--样式部分--> <style> .container { background: #aaa; color: blue; } </style>
一个简单的组件就完成了。
2.我们打开入口组件App.vue并把里面的代码替换成如下代码:
<template> <div id="app"> <img src="./assets/logo.png"> <!--使用组件--> <helloworld></helloworld> </div> </template> <script> import helloworld from './components/helloworld' export default { components: { helloworld } } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>
这个时候还要将router文件夹下的index.js里面的代码屏蔽。因为这个栗子还没涉及到路由功能。
3.紧接着我们就可以启动服务了,在命令行下输入:
npm run dev
如果不报错,说明编译成功了,就会在浏览器中看到如下页面:
新建的helloworld.vue这个组件就运行成功了,hello world !也就出世了。
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- vue学习记录
- vue-cli学习命令记录
- Vue学习记录(Day.5)
- vue学习记录 vue中引入样式文件
- Vue学习记录
- Vue学习记录—配置Axios及使用
- Vue 学习记录<2>
- Vue.js学习记录——二
- Vue学习笔记2-2 实现Hello World
- vue基础学习记录(三)
- 1.vue.js学习记录——生命周期
- 2.VUE前端框架学习记录二
- Vue学习记录(Day.3)
- 学习记录 | vue基础之声明式渲染“helloword”
- 3.VUE前端框架学习记录三:Vue组件化编码1
- vue.js中的各种问题记录(包括环境问题和学习笔记)
- Vue学习记录—初始Vue模块页面
- 【vue】vue组件化开发初体验-示例vue-loader-example学习记录
- vue.js个人学习记录
- vue 学习记录