百度掩码和布码在vue中使用

封装方法

// 百度广告
const bdMixin = {
     
  methods: {
     
    loadBDAd (l) {
     
      const r = window
      const d = document
      r._agl = r._agl || []
      r._agl.push(['production', l])
      var agl = d.createElement('script')
      agl.type = 'text/javascript'
      agl.async = true
      agl.src = 'https://fxgate.baidu.com/angelia/fcagl.js?production=' + l
      var s = d.getElementsByTagName('script')[0]
      s.parentNode.insertBefore(agl, s)
      // _agl && _agl.push(['track', ['success', { t: 3 }]])
    }
  }
}

export default bdMixin

页面使用

import bdMixin from '../../mixins/bd'
export default{
     
	mixins: [bdMixin],
	// 在表单预约成功后
	metodes:{
     
	   postMinUser({
      ...obj }).then(res => {
     
        if (res.status === 201) {
     
          // console.log('约成功')
          window._agl && window._agl.push(['track', ['success', {
      t: 3 }]])
        }
      }).catch(err => {
     
        // console.log(err.data, '错误的');
      })
    }, 300)
	}
}

你可能感兴趣的:(百度,广告,vue.js,javascript)