<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="js/axios.js"></script>
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<button @click="search">查询新闻信息</button>
</div>
<script>
new Vue({
el: "#app",
methods: {
search() {
axios.get("http://localhost:3000/posts")
.then(res => {//通过回调函数(参数函数)then来处理请求成功
console.log(res.data);
})
}
}
});
</script>
</body>
</html>
nodejs是一个js运行环境
1、验证是否安装成功
node -v
(输出版本号则成功)
2、进行相关配置)(以管理员身份运行)
npm config set prefix (nodejs安装目录)
npm config set prefix "D:\Nodejs"
3、验证配置是否成功
npm config set prefix
(输出 NodeJS 则成功)
4、切换npm淘宝镜像来加速(管理员)
npm config set registry https://registry.npm.taobao.org
1、
npm install -g @vue/cli
2、验证是否安装成功
vue --version
出现版本号就是成功了
差值表达式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="vue.js"></script>
<body>
<div id="app">
<div v-for="a in arr">{{arr}}</div>
</div>
</body>
<script>
new Vue({
el: "#app",
data: {
arr: ['a', 'b', 'c']
}
})
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="vue.js"></script>
<body>
<div id="app">
<div v-for="a in arr">{{a}}</div>//改动了这里
</div>
</body>
<script>
new Vue({
el: "#app",
data: {
arr: ['a', 'b', 'c']
}
})
</script>
</html>

npm run serve
访问http://localhost:8080/ 该默认网址会出现该页面
即以上页面
// utils.js
export default function add(a, b) {
return a + b;
}
// main.js
import add from './utils.js';
console.log(add(2, 3)); // 输出 5
export default
没有指定名称是因为它导出的是一个对象字面量(即一个没有具体名称的对象)。当使用 export default
导出时,可以直接将对象字面量作为默认导出的内容,而不需要为它指定一个特定的名称。
在这种情况下,代码中的 export default
导出的是一个包含组件选项的对象,并且没有为这个对象指定一个名称。这样做的好处是,其他模块在使用 import
关键字引入这个默认导出时,可以为它指定任意的名称,使其更具可读性和语义化。
不指定名称的另一个原因是,通过将对象字面量作为默认导出,可以更方便地在其他模块中进行引用和使用。通过 import
关键字,可以为默认导出指定任意的名称,使代码更加灵活和易于维护。
如果要导入一个没有名称的 export
,可以使用 import
语句,但是可以省略导入的变量名。
假设你有一个名为 myModule.js
的模块,并且在该模块中使用 export
导出了一个值,而没有为该导出指定名称。以下是导入这个没有名称的 export
的示例:
import './myModule.js';
在上述示例中,使用 import
语句导入了 myModule.js
模块,但并没有为导入的值指定变量名。这样做是为了执行 myModule.js
中的副作用,例如在模块中定义的全局变量、执行代码等。
需要注意的是,导入没有名称的 export
时,你不能直接使用导入的值,因为没有为其指定变量名。但是,它可以用作执行副作用的手段。例如,当导入的模块包含在浏览器环境中注册全局变量的代码时,可以使用这种方式导入模块,而不需要使用导入的值。
如果你需要使用导入的值,可以使用 import
语句为其指定一个变量名:
import myValue from './myModule.js';
console.log(myValue); // 使用导入的值
左原生 右为Element
npm install element-ui@2.15.3
1、在views中建element文件夹来存放
2、搭出vue文件所有内容
<template>
<div>
<!--button 样式-->>
<el-row>
<el-button>默认按钮</el-button>
<el-button type="primary">主要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="info">信息按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">危险按钮</el-button>
</el-row>
</div>
</template>
<script>
export default {
}
</script>
<style>
</style>
3、应用
<template>
<div>
<!-- <h1> {{ message }}</h1> -->
<element-view></element-view>//
</div>
</template>
<script>
import ElementView from './views/element/ElementView.vue'
export default {
components: { ElementView },
data() {
return {
message: "Hello vue"
}
},
methods: {
}
}
</script>
<style></style>
<!-- 自定义对话框二 -->
<el-button type="text" @click="dialogFVisible = true">打开嵌套表格的 Dialog</el-button>
<el-dialog title="收货地址" :visible.sync="dialogFVisible">
</el-dialog>
//该对话框根据@click来决定。通过dialog来决定对话框中有无内容
alert(JSON.stringify(this.form))
//通过JSON将对象转换成字符串
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/EmpView1',//在浏览器导航栏后面输入什么
name: 'home',//该路由的名字
component: () => import('../views/tilas/EmpView1.vue')//访问的路径
},
{
path: '/EmpView',
name: 'home1',
component: () => import('../views/tilas/EmpView.vue')//访问的路径
},
]
const router = new VueRouter({
routes
})
export default router
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{
path: '/',//默认的路径
name: 'home1',
component: () => import('../views/tilas/EmpView.vue')//访问的路径
},
{
path: '/EmpView1',//在浏览器导航栏后面输入什么
name: 'home',//该路由的名字
component: () => import('../views/tilas/EmpView1.vue')//访问的路径
},
{
path: '/EmpView',
name: 'home1',
component: () => import('../views/tilas/EmpView.vue')//访问的路径
},
]
const router = new VueRouter({
routes
})
export default router
// 以上功能都完成后,使用routeview标签来实现
<template>
<div>
<!-- <h1> {{ message }}</h1> -->
<!-- <element-view></element-view> -->
<!-- <emp-view></emp-view> -->
<router-view></router-view>
</div>
</template>
<script>
// import EmpView from './views/tilas/EmpView.vue'
// import ElementView from './views/element/ElementView.vue'
export default {
// components: { EmpView },
// components: { ElementView },
data() {
return {
message: "Hello vue"
}
}
}
</script>
<style></style>
<router-view>
是一个特殊的组件,用于渲染匹配到的路由组件。当你使用<router-view>
标签时,它会根据当前的路由路径匹配到对应的组件,并将其渲染到该位置。
在你提供的代码中,你创建了一个Vue Router实例,并定义了一些路由规则。每个路由规则都指定了一个路径和对应的组件。当访问特定的路径时,Vue Router会根据路由规则找到对应的组件,并将其渲染到<router-view>
标签所在的位置。
对应的组件。当访问特定的路径时,Vue Router会根据路由规则找到对应的组件,并将其渲染到<router-view>
标签所在的位置。