前言
- demo为
chnq/vue/vue/vue-demo
- 项目地址
初始化
- 参考这篇博客构建一个最简单的vue项目
- 启动项目后报错:
errors and 0 warnings potentially fixable with the --fix option.
- 解决方案:配置项目根目录下的package.json
| "lint": "eslint --fix --ext .js,.vue src", |
| |
- 自定义一个组件,添加到根组件后,启动项目报错:
Module Error (from ./node_modules/eslint-loader/index.js):
- 解决方案:项目根路径下新建
vue.config.js
| module.exports = { |
| lintOnSave: false |
| } |
| |
基础使用
| # 在components目录下新建一个子组件 UserList.vue |
| <template> |
| <div> |
| Hello!! |
| </div> |
| </template> |
| |
| <script> |
| export default { |
| |
| } |
| </script> |
| |
| <template> |
| <div> |
| <user-list/> |
| </div> |
| </template> |
| |
| <script> |
| import UserList from './components/UserList.vue' |
| export default { |
| name: 'App', |
| components: { |
| UserList, |
| } |
| } |
| </script> |
| |
| <template> |
| <div> |
| |
| <user-list/> |
| |
| {{msg}} |
| |
| <div id="two-way-binding"> |
| <p>{{ message }}</p> |
| <input v-model="message" /> |
| </div> |
| |
| <div id="conditional-rendering"> |
| <span v-if="seen">现在你看到我了</span> |
| </div> |
| |
| <div id="list-rendering"> |
| <ol> |
| <li v-for="todo in todos"> |
| {{ todo.text }} |
| </li> |
| </ol> |
| </div> |
| </div> |
| </template> |
| |
| <script> |
| import UserList from './components/UserList.vue' |
| export default { |
| name: 'App', |
| components: { |
| UserList, |
| }, |
| data() { |
| return { |
| msg: '文本', |
| message: 'Hello Vue!', |
| seen: true, |
| todos: [ |
| { text: 'Learn JavaScript' }, |
| { text: 'Learn Vue' }, |
| { text: 'Build something awesome' } |
| ] |
| } |
| }, |
| created(){ |
| console.log("生命周期!") |
| } |
| } |
| </script> |
| |
| <template> |
| <div> |
| |
| <a v-bind:href="myUrl" v-bind:title="myTitle" v-bind:id="myId">这是a标签</a><br> |
| |
| <a :href="myUrl">v-bind的缩写</a><br> |
| |
| <input type="text" v-on:blur="myBlur"><br> |
| |
| <button @click="mySubmit">v-on的缩写:v-on:替换成@</button> |
| </div> |
| </template> |
| |
| <script> |
| export default { |
| data(){ |
| return { |
| myUrl: 'www.baidu.com' |
| ,myTitle: '这是title_2' |
| ,myId: 'id2' |
| ,myUrl: 'https://www.baidu.com/' |
| } |
| }, |
| methods: { |
| myBlur(){ |
| console.log("失去焦点!"); |
| }, |
| mySubmit(){ |
| console.log("阻止提交!") |
| } |
| } |
| } |
| </script> |
| <template> |
| <div> |
| <input type="text" v-model="msg"><br> |
| <input type="text" v-model="name"> |
| </div> |
| </template> |
| |
| <script> |
| export default { |
| data() { |
| return { |
| msg: '', |
| name: '' |
| } |
| }, |
| watch: { |
| msg(oldValue,newValue){ |
| console.log("oldValue:", oldValue, ",newValue:", newValue); |
| } |
| ,name(oldval,newval){ |
| console.log("oldval:", oldval, ",oldval:", oldval) |
| this.getUser(newval) |
| } |
| }, |
| methods: { |
| getUser(name){ |
| |
| console.log("name:", name) |
| } |
| } |
| } |
| </script> |
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术