vue 引入外部js的变量、常量或方法

1,变量引用

    外部js:

        var s = "变量数据";

        export default{

            customData:function () {

                return s;

            }

        }

.vue实例文件

    import SM from "../../static/js/networkRequest"

        export default {

            data () {

                return{

                    newData:SM.customData()

                }

            }

        }   

2,方法调用

    外部js:

        function test(){

            console.log("tttttttttttttttttttt::::")

        }

        export {

            test

        }

    .vue实例文件

        import  { test} from "../../static/js/mathUtils"

        created(){

            this.test2();

        },

        methods: {

            test2(){

                test()

            }

        }

3,常量引用

      外部js:

        const S="dd"

        export {

            accMul,

            S

        }

     .vue实例文件

        import  { accMul,S } from  "../../static/js/mathUtils"

        export default {

            data () {

                return{

                    str:S

                }

            },

             created(){

              console.log("=====================::::" +accMul(2,4))

               console.log("=====================::::" +this.str)

             }

        }   

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,048评论 0 2
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,719评论 0 3
  • 2018.9.16 星期日,天气晴,地点北京 没有想到这里还有些日记的功能,以前总是在本子上写。想起小时候,老师布...
    面条水阅读 313评论 0 0
  • 宝贝,你好! 今天京都一日游,我们穿着KIMONO行走在这座古老的城市,有Tina和小步阿姨的专业相机拍了好多美照...
    安妮虾阅读 221评论 0 1
  • UITextField*searchField = [barvalueForKey:@"_searchField"...
    言己言阅读 1,520评论 0 0