v-model 与:value 区别
// v-model 不可以加其他值<input type="text" v-model="value">// :value 可以添加单位<inpit type="text" :value="value+'元'">
click.stop 组织事件冒泡
vue 设置全局变量
// before - vue2Vue.prototype.$http=()=>{}// after - vue3app.config.globalProperties.$http=()=>{}
vue获取外网ip地址
// 第一步 remote-jsrender(createElement){return createElement('script',{ attrs: { type: 'text/javascript', src: this.src }})},props: {src: { type: String, required: true},},//components:{"remote-js":{render(createElement){return createElement("script",{attrs:{type:"text/javascript",src:this.src}});},props:{src:{type:String,required:true},}}}// 第二步 组件中使用<remote-js src="http://pv.sohu.com/cityjson?ie=utf-8"></remote-js>// 调用相关方法获取 ipvar ip = returnCitySN["cip"];console.log(ip,"ip")
vue中引入Echarts
- 全局方式引入 ```javascript // 引入方式 // echarts 5.0 以前的版本 import echarts from ‘echarts’ // echarts 50 版本 import * as echarts from ‘echarts’
// 全局方式引入 // vue3 app.config.globalProperties.$echarts = echarts // vue2 Vue.prototype.$echarts = echarts
// 使用 var myChart = this.$echarts.init(document.getElementById(“main”));
- 挂载到$root```javascriptimport * as echarts from 'echarts'const app = createApp(App).mount('#app')app.echarts=echarts// 使用mounted(){let myChart = this.$root.echarts.init(document.getElementById("myChart"));}
- provide引入
import * as echarts from 'echarts'import { provide } from 'vue'export default {name: 'App',setup(){provide('ec',echarts)//provide},components: {}}// 使用let echarts = inject("ec");//引入onMounted(() => {let myChart = echarts.init(document.getElementById("main"));}
$emit
$emit 用于调用父组件中的方法
// childrenmethods:{childrenFun(){this.$emit("funname",this.value)}}// vue3 setupsetup(props,ce){}
<template><Children @funname="FatherFun"></Children></template><script>export default{methods:{FatherFun(parameter){// parameter 就是children 里面的this.value}}</script>
vue插件
i18n
Vue I18n 是 Vue.js 的国际化插件。它可以轻松地将一些本地化功能集成到你的 Vue.js 应用程序中。
